我试图从我的主模块调用不同模块中的不同子模块。
当我在最后做exit sub
时,只有"简短的1";将被创建。
如果我不把exit sub
放在每个调用之后,它将首先"brief1",并进一步在循环中,它将为每一行创建所有字母,而不是它需要的那个。
Dim r As Long
r = 6
Do Until IsEmpty(Cells(r, 1))
With Sheet1
If Sheet1.Range("C" & r) = "Brief 1" Then
Rappelbrief_1
ElseIf Sheet1.Range("C" & r) = "Brief 2" Then
Rappelbrief_2
ElseIf Sheet1.Range("C" & r) = "Brief 3" Then
Rappelbrief_3
ElseIf Sheet1.Range("C" & r) = "Brief BA" Then
Brief_BA
ElseIf Sheet1.Range("C" & r) = "Brief na tel contact" Then
Brief_opheffen_na_telefonisch_contact
ElseIf Sheet1.Range("C" & r) = "Brief tel. opheffing" Then
Brief_Tel_Opheffing
ElseIf Sheet1.Range("C" & r) = "Brief 1 + ophefform" Then
Rappelbrief_1
Brief_opheffen_na_telefonisch_contact
'Ophefform_PDF
End If
您的IsEmpty(Cells(r, 1))
没有工作表引用,这可能会导致问题。
试试这样:
Sub tester()
Dim c As Range
Set c = Sheet1.Range("A6")
Do While Len(c.Value) > 0
Select Case c.Offset(0, 2).Value
Case "Brief 1": Rappelbrief_1
Case "Brief 2": Rappelbrief_2
Case "Brief 3": Rappelbrief_3
'etc etc
Case "Brief 1 + ophefform"
Rappelbrief_1
Brief_opheffen_na_telefonisch_contact
End Select
Set c = c.Offset(1, 0) 'next row
Loop
End Sub