Hiding Rows Based on Data or Blanks

WireGuy8

New Member
Joined
Feb 7, 2022
Messages
18
I have a cell that has text data that filters the range I need. It works great when there is data in there. When that cell is blank, is does not filter out the range that has data.

sheet10.Activate
Range("D3").AutoFilter Field:=4, Criteria1:= _
"=*" & Range("Q1").Value & "*", Operator:=xlAnd

How can i get it to filter based on the data in the cell, but hide rows in the range when the cell is blank. The cell Q1 is the cell with the data that needs to be filtered and if that cell is blank, hide rows with data.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Do you mean you want to hide all rows if Q1 is blank?
 
Upvote 0
Ok, how about
VBA Code:
   With Range("Q1")
      If .Value = "" Then
         Range("D3").AutoFilter 4, "", xlAnd, "<>"
      Else
         Range("D3").AutoFilter 4, "*" & .Value & "*"
      End If
   End With
 
Upvote 0
Your post would work if there was not a if isblank statement. To get around that I might change the Q1 to B5 on sheet7 and still do the filtering on sheet 10 from my original post.
 
Upvote 0
Is there a formula in those cells?
If so what is it?
 
Upvote 0
Here is the formula in Q1 on sheet 10.

=IF(ISBLANK('Shield Wire'!B5),"",'Shield Wire'!B5)

I can also just use B5 from sheet 7 as the Reference data and then filter on sheet 10 as shown in my first post. I am just having problem getting this to work.
 
Upvote 0
Thanks for that, however it should not make any difference. The data should still be hidden.
Make sure that B5 is actually empty (no stray spaces etc), also do you have a formula in col D?
 
Upvote 0

Forum statistics

Threads
1,215,024
Messages
6,122,729
Members
449,093
Latest member
Mnur

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