![]() |
Change the range for a recordset?
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 |
Change the range for a recordset?
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 marthasanchez wrote: 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 |
All times are GMT +1. The time now is 01:56 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com