特定の列を下から検索する|Excel VBA |
次のサンプルは、入力ダイアログボックスに入力した値をA列の下から検索し、最初に見つかったセルをアクティブにします。
Sub Sample()
Dim FindStr As String
Dim i As Long
FindStr = InputBox("検索する文字列を入力してください。")
If Len(FindStr) = 0 Then Exit Sub
FindStr = "*" & FindStr & "*" '部分一致検索
For i = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1
With Cells(i, 1)
If .Value Like FindStr Then
.Activate
Exit For
End If
End With
Next i
End Sub