Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hiding rows based on cell contents

Status
Not open for further replies.

S4Tyler

Technical User
Jan 12, 2010
11
US
I need certain rows in a worksheet "Printsheet" to either be hidden or shown based on the contents of specific cells in another worksheet "Input".

I was thinking something like this but I am not having much success.

If Printsheet.Cells.Range(5, 5) = "A" Then
Printsheet.Rows("39:52").Hidden = True

I am pretty new to this so please don't hesitate to "dumb" down any suggestions you may have.

Thanks in advance for any help anyone can offer.

Tyler
 


Hi,

Why not use the AutoFilter? No need for VBA!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
The sheet that I need to hide certain rows on is formated to be printer friendly as building design criteria sheet when printed. Because of this, the page has several blank columns that need to remain to keep the format of the printed page generalized.

Here is what I have now:

Private Sub Worksheet_Activate()
Dim Count As Single

Dim Sheet2 As Worksheet
Set Sheet2 = Sheets("Input")

Dim Sheet3 As Worksheet
Set Sheet3 = Sheets("DesignCriteria_Engineering")

'for seismic
If Sheet2.Cells.Range(37, 5) = "A" Then
Sheet3.Rows("39:52").Hidden = True
Else: Sheet3.Rows("39:52").Hidden = False

End If

'for crane
If Sheet2.Cells.Range(58, 5) = "0" Then
Sheet3.Rows("53:56").Hidden = True
Else: Sheet3.Rows("53:56").Hidden = False

End If

'for mezzanine
If Sheet2.Cells.Range(65, 5) = "0" Then
Sheet3.Rows("57:62").Hidden = True
Else: Sheet3.Rows("57:62").Hidden = False

End If

End Sub


When I run this I get run-time error '1004'

 



On exactly what statement?

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 

Proper syntax -- not Range...
Code:
If Sheet2.Cells(37, 5) = "A" Then

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
The syntax fix got it going. Thanks for all your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top