Hiding Rows with Macros

M

maacmaac

I want to hide rows based on the value given in G4. Example: if G4=6,
then hide rows 17-25; if G4=3, then hide rows 14-20; if G4=11,
then hide rows 22-25.

I am using the following macro, but it does not work.


Sub Hide_Rows()
'
' Hide_Rows Macro
'

' Rows.Offset("A14:A25").EntireRow.Hidden = True
End Sub



Please help.

Thanks,

Attachment filename: hide rows.xls
Download attachment: http://www.excelforum.com/attachment.php?postid=383145
 
H

Harald Staff

Hi

Sub Hide_Rows()
Rows("14:25").Hidden = True
End Sub

I am not able to spot any linear logic from your 3 samples, so you (or anyone else
brighter than me) must take it from here.
 
E

Ed

Sub CheckandHide()

Dim strValue As String

strValue = Range("G4").Value

If strValue = 6 Then
Range("A17:A25").Select
Selection.EntireRow.Hidden = True
End If

If strValue = 3 Then
Range("A14:A20").Select
Selection.EntireRow.Hidden = True
End If

' etc and so forth for all your citeria

End Sub

HTH
Ed
 

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