VB Code to hide rows

L

Lost

I want a macro that hides a dyamic named range. For example:
A
1 unhide
2 unhide
3 unhide
4 hide
5 hide
6 hide
7 unhide

The hide/unhide are based on the contents of what is in column B, therefore
the rows that indicate hide won't be static. However the cells indicating
hide will always be next to each other (no overlap)... I was thinking that I
need to define a named range which would include the rows that indicate hide
in column A and then hide that named range. (ie in this case my named range
would consist of rows 4-6, but again it wont always be this way.) I have
numerous lines of data and do NOT want the macro to have to read through 4000
cells... I figured this would be much quicker! Thanks!
 
D

Don Guillett

Where the defined name range of hiderng is
=$a$1,$a$7,$a$21

or just put in sub without naming
range("a1,a7,a21").entirerow.hidden=true

Sub hidenamedrngrows()
Range("hiderng").EntireRow.Hidden = True
End Sub
 
L

Lonnie M.

Hi, what if you had the cells that you want to hide contain a blank
value (""). The solution could be pretty simple:

Sub uHide()
Cells.Rows.Hidden = False
Columns(1).EntireColumn.SpecialCells(xlBlanks).Rows.Hidden
End Sub


HTH--Lonnie M.
 
L

Lonnie M.

Correction:
  Columns(1).EntireColumn.SpecialCells(xlBlanks).Rows.Hidden

Should read:
Columns(1).EntireColumn.SpecialCells(xlBlanks).Rows.Hidden = True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top