Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA using Excel (If Statement) please help!!!

Status
Not open for further replies.

aordoqui

Computer
Joined
Jan 12, 2003
Messages
3
Location
US
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.
 
Put a command button on the sheet and use something like:

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
 
aordoqui,

Did it work OK for you?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top