【发布时间】:2016-07-15 12:29:44
【问题描述】:
我正在尝试将多个 "If"s 和一个 "For-Next" 语句组合在一个 "If" 中(代码如下)。不幸的是,我总是收到一条错误消息:“编译错误:没有 If 的其他情况”。你能看看我的代码有没有错误?
Sub Debugging()
Workbooks("Problem.xls").Worksheets(1).Activate
Cash_Rows = 5
Share_Rows = 6
If Cash_Rows <= Share_Rows Then
Range("A1:A" & Cash_Rows).Select
With Selection.Interior
.ThemeColor = xlThemeColorAccent6
.TintAndShade = 0.399975585192419
Count_Cash = Application.WorksheetFunction.CountIf(Range("A:A"), "L*")
For Each cell In Range("A1:A" & Cash_Rows)
If CStr(cell.Value) Like "L*" Then
Range("A" & cell.Row & ":" & "D" & cell.Row).Interior.Color = 65535
Dim Index As Integer
Index = Application.WorksheetFunction.Match(CStr(cell.Value), Range("F2:" & "F" & Share_Rows), 0)
Range("F" & Index & ":" & "I" & Index).Interior.Color = 65535
End If
Next
If Count_Cash = 0 Then
MsgBox "You do not have any matching ID+Amount between Cash and Shares booking. It's OK!"
Else
MsgBox "You have " & Count_Cash & " matching transactions. Check them!"
End If
Else
MsgBox "Do not worry. Be happy!"
End If
End Sub
提前感谢您的帮助!
【问题讨论】:
-
你在
.TintAndShade = 0.399975585192419之后缺少End With
标签: excel vba if-statement for-loop