编译错误; End With without With 虽然两者都在那里
Compile Error; End With without With although both are there
目前正在编写一个脚本,如果行中的特定单元格包含特定短语(该单元格包含的不仅仅是特定短语),则突出显示该行。但是,在尝试测试时,我看到了错误 "Compile Error: End With without With" 我可以在我的代码中同时看到 With 和 End With,尽管我可能已经查看它太久而没有注意到明显的错误。任何人都可以注意到代码中可能导致此问题的任何内容吗?
Sub Conversion()
Dim State As String
Dim County As String
Dim Date As String
Dim TC As String
Dim H As String
Dim Tmp As String
Dim m As Long
Dim x As Long
H = "not recognised"
With Sheets("Matched Date")
For Each cell In Sheet
m = UBound(Split(Rng.Value, H))
If m > 0 Then
Tmp = ""
For x = 0 To m - 1
Tmp = Tmp & Split(Rng.Value, H)(x)
.Characters(Start:=Len(Tmp) + 1, Length:=y).EntireRow.Color = RGB(252, 227, 3)
Tmp = Tmp & H
Next
End If
End With
编辑:对于这里的业余代码,我很抱歉,我没有受过训练,只是试图根据简单的在线视频和 google 指南来做这件事,因为我们没有其他人可以为我们做这件事。
如上所述,适当的代码缩进是您的朋友。这样做,您的代码看起来像
With Sheets("Matched Date")
For Each cell In Sheet
m = UBound(Split(Rng.Value, H))
If m > 0 Then
Tmp = ""
For x = 0 To m - 1
Tmp = Tmp & Split(Rng.Value, H)(x)
.Characters(Start:=Len(Tmp) + 1, Length:=y).EntireRow.Color = RGB(252, 227, 3)
Tmp = Tmp & H
Next
End If
End With
这样,很容易发现您的第一个 For
循环缺少结束 Next
。
此错误消息和类似的错误消息可能有点误导。它基本上意味着 "This code somehow misses a closing 'bracket'",如果您将 With/End With
、For/Next
、Select/End Select
等对视为 opening/closing 括号对。
目前正在编写一个脚本,如果行中的特定单元格包含特定短语(该单元格包含的不仅仅是特定短语),则突出显示该行。但是,在尝试测试时,我看到了错误 "Compile Error: End With without With" 我可以在我的代码中同时看到 With 和 End With,尽管我可能已经查看它太久而没有注意到明显的错误。任何人都可以注意到代码中可能导致此问题的任何内容吗?
Sub Conversion()
Dim State As String
Dim County As String
Dim Date As String
Dim TC As String
Dim H As String
Dim Tmp As String
Dim m As Long
Dim x As Long
H = "not recognised"
With Sheets("Matched Date")
For Each cell In Sheet
m = UBound(Split(Rng.Value, H))
If m > 0 Then
Tmp = ""
For x = 0 To m - 1
Tmp = Tmp & Split(Rng.Value, H)(x)
.Characters(Start:=Len(Tmp) + 1, Length:=y).EntireRow.Color = RGB(252, 227, 3)
Tmp = Tmp & H
Next
End If
End With
编辑:对于这里的业余代码,我很抱歉,我没有受过训练,只是试图根据简单的在线视频和 google 指南来做这件事,因为我们没有其他人可以为我们做这件事。
如上所述,适当的代码缩进是您的朋友。这样做,您的代码看起来像
With Sheets("Matched Date")
For Each cell In Sheet
m = UBound(Split(Rng.Value, H))
If m > 0 Then
Tmp = ""
For x = 0 To m - 1
Tmp = Tmp & Split(Rng.Value, H)(x)
.Characters(Start:=Len(Tmp) + 1, Length:=y).EntireRow.Color = RGB(252, 227, 3)
Tmp = Tmp & H
Next
End If
End With
这样,很容易发现您的第一个 For
循环缺少结束 Next
。
此错误消息和类似的错误消息可能有点误导。它基本上意味着 "This code somehow misses a closing 'bracket'",如果您将 With/End With
、For/Next
、Select/End Select
等对视为 opening/closing 括号对。