Hide rows in a range if cell is blank (has formulas, but no value)

sdoppke

Well-known Member
Joined
Jun 10, 2010
Messages
647
Well the title pretty much said it all. I am looking have a macro that hides the rows in a column range. Not based on the entire column, but say if there are cells within A25:A50 that are empty (all will have formulas) then hide entire row of those empty cells.

I wont be able to use autofilter, because there is no consitency in the cloumns or rows.

Thanks a ton in advance.

sd
 
Hi sd,

Could you try this macro?

Just run it normally and see if it colors yellow the correct rows you want hidden. If so then just replace the part in red by ".hidden=true" (without the quotes)
Rich (BB code):
Sub hide()
Dim lr As Long, e As Range
lr = Range("A" & Rows.Count).End(xlUp).Row
On Error Resume Next
For Each e In Range("A1:A" & lr).SpecialCells(xlFormulas)
 If Len(e) = 0 Then Rows(e.Row).Interior.Color = vbYellow
Next
On Error GoTo 0
End Sub

Thnank you again for replying and hangin in there. Its weird, no cells turn yellow. See the macro below. I have tried it on only 10 rows (A23:A32) in Column A. These 10 cell are blanck except they contain formulas, and yet they still do not turn yellow. Any ideas where im going wrong?

Code:
Sub hide()
Dim lr As Long, e As Range
lr = Range("A" & Rows.Count).End(xlUp).row
On Error Resume Next
For Each e In Range("A23:A32" & lr).SpecialCells(xlFormulas)
 If Len(e) = 0 Then Rows(e.row).Interior.Color = vbYellow
Next
On Error GoTo 0
End Sub
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi,

If you want to pre-specify the range to be used, you should use
Code:
Range("A23:A32")
rather than
Range("A23:A32" & lr)
although unlikely this is the reason for no yellow showing.

I guess the term "blank" in Excel has a bit of flexibility depending in who is using it and what is really in the cell(s).

When I tested that code I just used simple formulas such as
=IF(1=2,"","")
where a "blank" cell is one that displays "".
The code worked OK for me in such case, because of the
Code:
IF len(e) = 0 ...
line.

However there's other ways of getting blank cells, such as if you use the formula =IF(1=2,char(160),char(160)) or similar, such as just =Char(160).

The non-printing character Char(160) (or Chr(160) in VBA) is one that sometimes causes problems when looking at a blank cell it is also assumed to be empty.

However, my short answer is that my code as posted only looks at one version of a "blank" cell. I just don't have time for a while to look at the problem more closely for a while, but if you don't get other answers then I'll have another look at it.

As a very quick attempt, you might rerun the code with the relevant line changed to
Code:
If Len(e) = 0 Or e=Chr(160)Then Rows(e.Row).Interior.Color = vbYellow
although that may or may not work for you.
 
Upvote 0

Forum statistics

Threads
1,215,103
Messages
6,123,106
Members
449,096
Latest member
provoking

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