VBA如何快速定位到某个单元格,求大神指点迷津!!!
如图,我试图找出最后一个"A"的行号,最后一个"B"的行号,最后一个"C"的行号,由于"A"的数量太庞大,于是我写了如下代码:
Sub ABC()
Dim i, RowSum, A_LastNum, B_LastNum, C_LastNum As Long
RowSum = Range("A1", Range("A1").End(xlDown)).Cells.Count
i = RowSum + 1
Do
i = i - 1
If (Cells(i, 1).Value = "C") And (Cells(i + 1, 1).Value <> "C") Then
C_LastNum = i
Else
If (Cells(i, 1).Value = "B") And (Cells(i + 1, 1).Value <> "B") Then
B_LastNum = i
Else
If (Cells(i, 1).Value = "A") And (Cells(i + 1, 1).Value <> "C") Then
A_LastNum = i
Exit Do
End If
End If
End If
Loop
End Sub
Sub ABC()
' 这是一个宏
Dim i, RowSum, A_LastNum, B_LastNum, C_LastNum As Long
ActiveSheet.Cells.Find(What:="B").Activate
A_LastNum = Selection.Row - 1
ActiveSheet.Cells.Find(What:="C").Activate
B_LastNum = Selection.Row - 1
For i = Selection.Row To 65534
If ActiveSheet.Cells(i, 1).Value = "C" And ActiveSheet.Cells(i + 1, 1).Value <> "C" Then
C_LastNum = i
Exit For
End If
Next i
Debug.Print A_LastNum, B_LastNum, C_LastNum
End Sub