VBAを使用して、列Bに値「X」が含まれるすべての行を削除しようとしています。ただし、次の 3 つの問題があります。
- VBA コードで、cells.find メソッドを使用してアクティブ セルから次のセル (B3) に移動できません (以下のコードを参照)。
- 私のコードは、値「X」が列 B にある行全体を削除しません。
- 列 B のデータ量は変動する可能性があります。今日は B10 で終了する場合もあれば、明日は B100 で終了する場合もあります (以下のスクリーン ショットを参照)。
どんな援助でも大歓迎です。
Sub RemoveRows()
Dim strLookFor As String
Dim strRow As String
Worksheets("Sheet1").Range("B2").Activate
strLookFor = "X"
strRow = Range("B2").Address
Do Until ActiveCell.Value = ""
MsgBox (ActiveCell.Value)
If ActiveCell.Value = strLookFor Then
Rows.Delete (strRow)
End If
strRow = Cells.Find(what:=strLookFor).Address
Loop
MsgBox ("Deleted all rows with value " & strLookFor)
End Sub