vba Excel VBA编译错误Else没有If
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21924497/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:50:18 来源:igfitidea点击:
Excel VBA Compile Error Else without If
提问by user3006276
I try to run a code when column "L" and column "V" stated "Completed" on both. Then column "W" will show "Completed" else it will show "incompleted" but it show compile error "Else withou if".
当“L”列和“V”列均表示“已完成”时,我尝试运行代码。然后列“W”将显示“已完成”,否则它将显示“未完成”但它会显示编译错误“Else withoutou if”。
Below is my code
下面是我的代码
Sub OverallStatus()
Dim x As Long
Dim lastrow As Long
With Sheet1
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
lastrow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
Else
lastrow = 1
End If
For x = 2 To lastrow
If .Range("L" & x) = "Completed" And .Range("V" & x) = "Completed" Then
.Range("W" & x) = "Completed"
Else: .Range("W" & x) = "Incomplete"
End If
Next
End With
End Sub
采纳答案by PatricK
Things to change on your code:
更改代码的内容:
- New line characterafter
Then
, or move this back up at end of theIf
- Insert
End If
before theNext
- Replace
End If
above theEnd Sub
withEnd With
- 之后的换行符
Then
,或在结尾处将其移回If
- 在
End If
前面插入Next
- 替换
End If
上述End Sub
用End With