固定和#x201C;编译错误:下一步不带for”;VBA中的错误?
我似乎弄不懂这个。我想搜索我的工作表,看看是否有“=REF!”以及是否有不运行我的代码的错误。问题是,当我运行它时,代码中的错误围绕着下一部分固定和#x201C;编译错误:下一步不带for”;VBA中的错误?,vba,excel,Vba,Excel,我似乎弄不懂这个。我想搜索我的工作表,看看是否有“=REF!”以及是否有不运行我的代码的错误。问题是,当我运行它时,代码中的错误围绕着下一部分 Sub logs() Dim numberofsheets As Integer For numberofsheets = 1 To 5 Set checkRange = Sheets("Final Four").Range("A1:Z100") If IsError(CheckCell) And _ CVErr(CheckCell
Sub logs()
Dim numberofsheets As Integer
For numberofsheets = 1 To 5
Set checkRange = Sheets("Final Four").Range("A1:Z100")
If IsError(CheckCell) And _
CVErr(CheckCell) = CVErr(2023) Then
Exit Sub
End If
Next
Set checkRange = Sheets("Top Left").Range("A1:Z100")
If IsError(CheckCell) And _
CVErr(CheckCell) = CVErr(2023) Then
Exit Sub
End If
Next
Set checkRange = Sheets("Bottom Left").Range("A1:Z100")
If IsError(CheckCell) And _
CVErr(CheckCell) = CVErr(2023) Then
Exit Sub
End If
Next
Set checkRange = Sheets("Top Right").Range("A1:Z100")
If IsError(CheckCell) And _
CVErr(CheckCell) = CVErr(2023) Then
Exit Sub
End If
Next
Set checkRange = Sheets("Bottom Right").Range("A1:Z100")
If IsError(CheckCell) And _
CVErr(CheckCell) = CVErr(2023) Then
Exit Sub
End If
ActiveSheet.EnableCalculation = True
lst = Sheets("data").UsedRange.Rows.Count
x = lst + 1
' Display a message when one of the designated cells has been
' changed.
' Place your code here.
Sheets("data").Range("A" & x) = ActiveSheet.Range("I3")
Sheets("data").Range("B" & x) = ActiveSheet.Range("I4")
End Sub
不知道怎么做。我是个新手 我认为您正在寻找类似下面的
for
循环的东西来在代码中实现:
Sub logs()
Dim Sht As Worksheet
Dim checkRange As Range, CheckCell As Range
For Each Sht In ThisWorkbook.Sheets ' loop through your worksheets
With Sht
Select Case .Name ' check for the sheet.Name
Case "Final Four", "Top Left", "Bottom Left", "Top Right", "Bottom Right"
Set checkRange = .Range("A1:Z100") ' set the range for the current sheet
For Each CheckCell In checkRange
If IsError(CheckCell) Then
If CheckCell.Value = CVErr(2023) Then Exit Sub
' you can use the following syntax as well
If CheckCell.Value = CVErr(xlErrRef) Then Exit Sub
End If
Next CheckCell
Set checkRange = Nothing
Case Else
' do nothing
End Select
End With
Next Sht
' rest of your code
End Sub
您只有一个
For
语句,但有四个Next
语句。删除三条下一条
语句。好吧,我该怎么做?@YowE3K哇,你今天早上跑得很快实际上,你似乎根本没有使用循环。因此,只需删除一个For
语句和四个Next
语句即可。请阅读-总结是,这不是一种向志愿者致辞的理想方式,可能会对获得答案产生反作用。请不要将此添加到您的问题中。@YowE3K tru that,刚刚用另一个场景再次测试了它。它说如果iError(CheckCell)和CVErr(CheckCell)=CVErr(2023)存在错误Then@YowE3K我喜欢很多线路,我按数量收费(线路数量)不合格如果我想刷新所有的工作表,那么有时就没有a=REF!然后我的代码就可以工作了?因为现在我所有的代码都在一个刷新按钮上,我希望我的数据每次都刷新,不管我什么时候按下刷新按钮,但是如果数据有a=REF!然后不将我的i3和i4输入到我的数据中sheet@YowE3K如果CheckCell.Value=CVErr(xlErrRef)