Change the range for a recordset?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to delete the rows with a positive number in a specific column. The
recordset will vary each time it is run. How do i change the range?



Sub click()
Dim i As Integer
Sheet1.Select
Sheet1.Range("a2:b6").Select
For i = 2 To 6
Cells(i, 2).Select
If Sheet1.Cells(i, 2) > 0 Then Sheet1.Rows(i).Delete
Next i
End Sub
Exit Sub
 
It depends on what the criteria for the recordset is. Here is a
solution assuming you want the macro to operate on the value in the
first column of the selected range:

Sub click()
Dim i As Long
With Selection
For i = .Cells(1,1).Row + .Rows.Count - 1 to .Cells(1,1).Row Step
- 1
If .Cells(i,1) > 0 Then .Cells(i,1).EntireRow.Delete
Next
End With
End Sub

Charles Chickering
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top