VBA Q

cfree36

Board Regular
Joined
Oct 5, 2005
Messages
175
I am trying to delete all the rows with a 1 in a specified range

I was trying to use this code:
Code:
'    For Each c In Sheets("sheet1").Range("FILTERRANGE")
'        If c.Value = 1 Then
'        c.Select
'        Selection.EntireRow.Delete
'        End If
'    Next c

It runs but the rows with 1 in them do not delete?

I would appreciate any help here....
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Code:
If c.Value = "1" Then
could help if the values are text.
Another option is use val(c.value)to convert it to an integer.

Note also, that you are running your loop from top to bottom, which means that if any rows are actually deleted, it skips the row after every row deleted.
 
Upvote 0
I tried and it works for me? Is there a named range area setup "FILTERRANGE"? Also is the 1 in a cell by itself? Because that is what this code is looking for
 
Upvote 0
there is a range named filterrange, each cell has either a 0 or a 1 based on an IF formula.

I very well could be skipping rows... how do I make the code run from bottom to top?
 
Upvote 0
Code:
    Dim i As Integer, j As Integer
    
    With Sheets("Sheet1").Range("test")
    For i = .Rows.Count - 1 To 0 Step -1
        For j = .Columns.Count - 1 To 0 Step -1
            If Val(Cells(.Row, .Column).Offset(i, j).Value) = 1 Then
                Cells(.Row, .Column).Offset(i, j).EntireRow.Delete
            End If
        Next j
    Next i
    End With
 
Upvote 0
THANKS.
When I get a second I'll give that a try as well.
Sorry for the delayed thanks... it's been crazy at work this week!

THANKS AGAIN!
 
Upvote 0

Forum statistics

Threads
1,214,549
Messages
6,120,149
Members
448,948
Latest member
spamiki

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top