【发布时间】:2016-09-14 07:03:45
【问题描述】:
我有一个名为“checkConvert”的方法,它应该返回一个字符串。
我创建了一个 For 循环,它在循环结束时返回一个值作为 checkConvert。此外,在该 For 循环中,我设置了一个 Case,在该 Case 中,还有另一个 For 循环,其中包含 If 语句。在这些 If 语句中,我也尝试将值作为 checkConvert 返回,但它根本不起作用。
For i = val To lastColumn_source
For j = 1 To 3
Dim cellValue As String
cellValue = salesSource.Cells(j, i).Value
Select Case i
Case 1
Dim match As Boolean
match = False 'Default is false.
'Equating two cells = false.
For x = 1 To lastRow_check
If cellValue = sourceCheck.Cells(x, 1) Then
CRMDest.Cells(j, 2) = newName
match = True 'Match is found. Thus, true.
End If
If x = lastRow_check And match = False Then
checkConvert = newName 'Supposed to return
'value. Doesn't
'work.
MsgBox checkConvert 'But MsgBox works.
End If
Next x
Case 2 'Several more cases follow.
Case 13
checkConvert = "End of Program." 'Returns String
'to "end program."
'This one works.
End Select
checkConvert = "Move." 'This return also
'works.
Next j
Next i
【问题讨论】:
标签: vba excel if-statement for-loop return