这是你正在尝试的吗?
With shtSAP
Set rngSAP = .Range(.Cells(1, 1), .Cells(rowsSAP, colsSAP))
For Each cellSAP In rngSAP.Rows
If Cells(cellSAP.Row, 2).Value = "03" Then
MsgBox Cells(cellSAP.Row, 2).Value
End If
Next
End With
完整示例
Sub Sample()
Dim shtSAP As Worksheet
Dim rngSAP As Range
Dim cellSAP
Dim rowsSAP As Long, colsSAP As Long
Set shtSAP = ActiveSheet
rowsSAP = 5: colsSAP = 5
With shtSAP
Set rngSAP = .Range(.Cells(1, 1), .Cells(rowsSAP, colsSAP))
For Each cellSAP In rngSAP.Rows
'Debug.Print Cells(cellSAP.Row, 2).Address
If Cells(cellSAP.Row, 2).Value = "03" Then
MsgBox Cells(cellSAP.Row, 2).Value
End If
Next
End With
End Sub
或者这个?
Sub Sample()
Dim shtSAP As Worksheet
Dim rngSAP As Range
Dim cellSAP
Dim rowsSAP As Long, colsSAP As Long
Set shtSAP = ActiveSheet
rowsSAP = 5: colsSAP = 5
With shtSAP
Set rngSAP = .Range(.Cells(1, 1), .Cells(rowsSAP, colsSAP))
For Each cellSAP In rngSAP.Rows
'Debug.Print cellSAP.Cells(, 2).Address
If cellSAP.Cells(, 2).Address = "03" Then
MsgBox Cells(cellSAP.Row, 2).Value
End If
Next
End With
End Sub