如果符合条件,写下“串”然后转到下一个

我有这条线:

If UCase(Sheets("DebitCard_Check").Range("G" & i).Value) Like "*TAX*" Then GoTo Skip1 

我需要的是插入这样的东西:

 IF condition is met, write "string" Then GoTo Skip1 

如果不满足条件,上面应该继续正常执行其余的代码。

我应该如何处理语法?

我尝试了一堆东西。 否则,ElseIF始终将对象填充为:

 (Sheets("DebitCard_Check").Range("G" & i).Value) = "string" 

这给了我很多错误。 没有IF的EndIF期望的语句,对象,行等

*********************************编辑1 *************** *********************

这是整个代码 – 修改的build议:

 Sub Categories_Update() Dim lastrow As Long, lastrow2 As Long Dim i As Integer, j As Integer Dim PatternFound As Boolean Call speedup lastrow = Sheets("Rules").Range("A" & Rows.Count).End(xlUp).Row lastrow2 = Sheets("DebitCard_Check").Range("L" & Rows.Count).End(xlUp).Row For i = 4 To lastrow2 ' *** This is where we can insert, a conditional that causes the row to get skipped based on 'column G being "CYRRILIC TEXT" - aka Auto Tax - this conditional sends it to the part "Skip1" down below If UCase(Sheets("DebitCard_Check").Range("G" & i).value) Like "*TAX*" Then Sheets("DebitCard_Check").Range("M" & i).value = "Automatic Tax" GoTo Skip1 PatternFound = False j = 1 Do While PatternFound = False And j < lastrow j = j + 1 If UCase(Sheets("DebitCard_Check").Range("L" & i).value) Like "*" & UCase(Sheets("Rules").Range("A" & j).value) & "*" Then Sheets("DebitCard_Check").Range("M" & i).value = Sheets("Rules").Range("C" & j).value PatternFound = True End If Loop Skip1: Next i Call normal End Sub Public Sub speedup() Application.ScreenUpdating = False Application.DisplayStatusBar = False Application.Calculation = xlCalculationManual Application.EnableEvents = False End Sub Public Sub normal() Application.ScreenUpdating = True Application.DisplayStatusBar = True Application.Calculation = xlCalculationAutomatic Application.EnableEvents = True End Sub 

不幸的是,这给了我一个错误 – > 编译错误:下一个没有

这是你应该这样做的:

 If UCase(Sheets("DebitCard_Check").Range("G" & i).value) Like "*TAX*" Then Sheets("DebitCard_Check").Range("G" & i).value = "string" GoTo Skip1 End If 

[编辑]

你应该在你的代码中做适当的缩进 – 你会更容易find这样的错误。 您忘记closuresFor ... Next语句。

我发现你的代码中还有一个错误。 你应该移动这两行:

 PatternFound = False j = 1 

GoTo Skip1标签之前。 否则,他们将永远不会被执行。

下面是你的代码,纠正所有这些错误:

 Sub Categories_Update() Dim lastrow As Long, lastrow2 As Long Dim i As Integer, j As Integer Dim PatternFound As Boolean Call speedup lastrow = Sheets("Rules").Range("A" & Rows.Count).End(xlUp).Row lastrow2 = Sheets("DebitCard_Check").Range("L" & Rows.Count).End(xlUp).Row For i = 4 To lastrow2 ' *** This is where we can insert, a conditional that causes the row to get skipped based on 'column G being "CYRRILIC TEXT" - aka Auto Tax - this conditional sends it to the part "Skip1" down below If UCase(Sheets("DebitCard_Check").Range("G" & i).value) Like "*TAX*" Then Sheets("DebitCard_Check").Range("M" & i).value = "Automatic Tax" 'NOTE: Those two lines must be before [GoTo Skip1]. Otherwise, ----------| 'they won't be executed. '| PatternFound = False '| j = 1 '| '------------------------------------------------------------------------| GoTo Skip1 End If Do While PatternFound = False And j < lastrow j = j + 1 If UCase(Sheets("DebitCard_Check").Range("L" & i).value) Like "*" & UCase(Sheets("Rules").Range("A" & j).value) & "*" Then Sheets("DebitCard_Check").Range("M" & i).value = Sheets("Rules").Range("C" & j).value PatternFound = True End If Loop Skip1: Next i Call normal End Sub Public Sub speedup() Application.ScreenUpdating = False Application.DisplayStatusBar = False Application.Calculation = xlCalculationManual Application.EnableEvents = False End Sub Public Sub normal() Application.ScreenUpdating = True Application.DisplayStatusBar = True Application.Calculation = xlCalculationAutomatic Application.EnableEvents = True End Sub