Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock 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
Jan 12, 2003
3
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.
 
Replies continue below

Recommended for you

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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor