我正在尝试让我的VBA代码循环遍历所有单元格,并在每次遇到单元格中的特定文本时将第二张中已存在的数字的数量减1 . 但是,每当我按步骤运行循环时,它似乎跳过下一个j并且每次都直接进入下一行,这是下一行 . 我的代码是否存在某种格式错误?
Sub DeleteSAC()
Dim count As Integer
Dim i As Integer
Dim j As Integer
Sheets(1).Select
lastRow = ActiveSheet.Cells(Rows.count, "B").End(xlUp).Row
'have to keep data in a table for this to actually work as it ctrls+left to the table, which will end where the very last text of any row is
lastColumn = ActiveSheet.Cells(1, Columns.count).End(xlToLeft).Column
count = Sheet2.Cells(1, 7).Value
i = 2
j = lastColumn
For i = 2 To lastRow
For j = lastColumn To 1
If Sheet1.Cells(i, j) = "SAC" Then
count = count - 1
GoTo NextIteration
End If
Next j
NextIteration:
Next i
Sheet2.Cells(1, 7) = count
End Sub
1 回答
试试这个:-