dansmith88
08-16-2012, 01:27 AM
Hi all,
I am new to vba and have created a loop to work through my data to delete all rows with an entry of texas in the state column. My problem arises though when i have an entry of texas consecutively. Does anyone have any ideas on how I can solve this problem? Maybe by using a nested loop? Any suggestions would be massively appreciated. Below you can see my code and an example of the table i am using.
Cheers
Sub Texas()
Dim sRow As Integer
sRow = 2
Cells(sRow, 5).Select
Do Until IsEmpty(ActiveCell.Value)
If ActiveCell.Value = "texas" Then
ActiveCell.Select
Selection.EntireRow.Delete
End If
sRow = sRow + 1
Cells(sRow, 5).Select
Loop
End Sub
the table is below
ErickAltenwerth77amariburghtexasotherno16Never tried itdemondSteuber35east isabellvilletexasSalmonyes18What is sushi?MARCIAdeckow47hoegerboroughNorth carolinatroutno18Hate it
I am new to vba and have created a loop to work through my data to delete all rows with an entry of texas in the state column. My problem arises though when i have an entry of texas consecutively. Does anyone have any ideas on how I can solve this problem? Maybe by using a nested loop? Any suggestions would be massively appreciated. Below you can see my code and an example of the table i am using.
Cheers
Sub Texas()
Dim sRow As Integer
sRow = 2
Cells(sRow, 5).Select
Do Until IsEmpty(ActiveCell.Value)
If ActiveCell.Value = "texas" Then
ActiveCell.Select
Selection.EntireRow.Delete
End If
sRow = sRow + 1
Cells(sRow, 5).Select
Loop
End Sub
the table is below
ErickAltenwerth77amariburghtexasotherno16Never tried itdemondSteuber35east isabellvilletexasSalmonyes18What is sushi?MARCIAdeckow47hoegerboroughNorth carolinatroutno18Hate it