Hide and then Delete Hidden Rows based on a Cell Value

WSBirch

Board Regular
Joined
Apr 10, 2018
Messages
59
Office Version
  1. 365
Platform
  1. Windows
Hi all,
I've been working on this all day trying various solutions I've found online here and for whatever reasons, probably user error, I'm just not able to get them to run correctly. Mostly no errors, just not performing the VBA.

I have at least 500 rows of data. Usually anywhere from 500 - 3000 rows at any given time.

In column "AI", I have either a value of " 0 " or " 1 ". I would like all rows that have a " 0 " in column "AI" to be hidden. Once all rows are hidden, then delete all hidden rows.

If this is of any impact, it's doing this in a table.
The table is refreshed, then rows hidden, and then hidden rows deleted. That's the entire macro I'm trying to create if possible.

All help would be greatly appreciated, thank you!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try this
(If the rows are going to be deleted it makes no sense to hide them.)

VBA Code:
Sub DeleteRows_4()
  With ActiveSheet
      .Columns("AI").Replace what:=0, replacement:="#N/A", Lookat:=xlWhole
      On Error Resume Next
      .Columns("AI").SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Delete
  End With
End Sub
 
Upvote 0
Actually, yeah, no reason to hide the rows if I can just delete them. I definitely like that.

Unfortunately, none of the rows are deleted. Nothing actually happens other than the refresh.
The values in the column AI are formulas. I know Excel can get hinky with that kind of thing. Here's the formula in one of those cells:

Code:
=VALUE(IF(OR([@SchShipDate]<TODAY(),[@SchShipDate]>TODAY()+14),0,1))


Here's the full code that I'm using right now. I don't receive any kind of errors. It completes the whole macro, but nothing happens other than just refreshing the query.

VBA Code:
Sub Refresh()

    Sheets("Sheet1").Select
    Range("Current_data_without_product_details__2[[#Headers],[ORDNO]]").Select
    Selection.ListObject.QueryTable.Refresh BackgroundQuery:=False
    
      With ActiveSheet
      .Columns("AI").Replace what:=0, replacement:="#N/A", Lookat:=xlWhole
      On Error Resume Next
      .Columns("AI").SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Delete
      End With
 
End Sub
 
Upvote 0
Assuming your header is in row 1, try:

VBA Code:
Sub DeleteRows_5()
  Dim lr
  lr = Range("AI" & Rows.Count).End(xlUp).Row
    With Range("A1:AI" & lr)
        .AutoFilter Field:=35, Criteria1:="=0"
        ActiveSheet.AutoFilter.Range.Offset(1, 0).EntireRow.Delete
    End With
    Range("A1").AutoFilter
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,225,210
Messages
6,183,611
Members
453,174
Latest member
circusnight

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