I have the following table:
a b c d
-------
1|- - x -
2|- - - -
3|- - x -
4|- - - -
I want to write VBA that will delete those rows where the value in column c = "x". I need to write it so that the code will work on any table (using CurrentRegion or UsedRange).
I tried the following, but it didn't work properly; it skipped row 3.
Sub Delete_X()
Dim tbl As Object
Dim rw As Object
Dim DateRet
Worksheets("Sheet1").Range("a1").Activate
Set tbl = ActiveCell.CurrentRegion
For Each rw In tbl.Rows
DateRet = rw.Cells(1, 3).Value
If DateRet = "x" Then rw.Delete
Next
End Sub
Any help would be greatly appreciated.
a b c d
-------
1|- - x -
2|- - - -
3|- - x -
4|- - - -
I want to write VBA that will delete those rows where the value in column c = "x". I need to write it so that the code will work on any table (using CurrentRegion or UsedRange).
I tried the following, but it didn't work properly; it skipped row 3.
Sub Delete_X()
Dim tbl As Object
Dim rw As Object
Dim DateRet
Worksheets("Sheet1").Range("a1").Activate
Set tbl = ActiveCell.CurrentRegion
For Each rw In tbl.Rows
DateRet = rw.Cells(1, 3).Value
If DateRet = "x" Then rw.Delete
Next
End Sub
Any help would be greatly appreciated.