ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VB Code to hide rows (https://www.excelbanter.com/excel-programming/417162-vbulletin-code-hide-rows.html)

Lost

VB Code to hide rows
 
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!


Don Guillett

VB Code to hide rows
 
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


--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Lost" wrote in message
...
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!



Lonnie M.

VB Code to hide rows
 
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).Row s.Hidden
End Sub


HTH--Lonnie M.

Lonnie M.

VB Code to hide rows
 
Correction:
* Columns(1).EntireColumn.SpecialCells(xlBlanks).Row s.Hidden


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


All times are GMT +1. The time now is 05:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com