VBA using Excel (If Statement) please help!!!
VBA using Excel (If Statement) please help!!!
(OP)
I need help
I am trying to make an if statment that deletes the entire row if a cell's value in that row is less than 100.
Example: I have a list of people with all sorts of information on them in separate columns, age is one of the columns. I want to delete the person or row if that person is, lets say, under the age of 100.
I am trying to make an if statment that deletes the entire row if a cell's value in that row is less than 100.
Example: I have a list of people with all sorts of information on them in separate columns, age is one of the columns. I want to delete the person or row if that person is, lets say, under the age of 100.





RE: VBA using Excel (If Statement) please help!!!
Private Sub CommandButton1_Click()
Dim myrange As Range
Dim myrange2 As Range
Dim rowcounter As Long
Set myrange = Worksheets("Sheet1").Range("A1:c100")
For rowcounter = 100 To 1 Step -1
If myrange.Cells(rowcounter, 2).Value > 50 Then
Set myrange2 = myrange.EntireRow(rowcounter)
myrange2.Delete
End If
Next
End Sub
Where the 2 is the column you are testing
RE: VBA using Excel (If Statement) please help!!!
Did it work OK for you?