Code for button to hide/unhide rows

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm having problems with this code. I've a worksheet for all levels of user.
Rows A1-G7 = header, Rows 8+ & Columns A-G = user data, Column G as trigger.
Would like to have Sub Button1_Click() to hide rows, if date or data in G;
and have a second button Sub Button2_Click() to unhide all. I'm close but no
cigar.
 
Something like ....??

Sub HideG()
lastrow = Cells(Rows.Count, "G").End(xlUp).Row
For i = 7 To lastrow
If Cells(i, "G") <> "" Then Rows(i).Hidden = True
Next i
End Sub

Sub unhideG()
Rows.Hidden = False
End Sub
 
Or one macro for both jobs

Sub HideG()
lastrow = Cells(Rows.Count, "G").End(xlUp).Row
For i = 7 To lastrow
Rows(i).Hidden = Cells(i, "G").Value <> ""
Next i
End Sub


--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)
 
Thanks both work. Just had to assign header as it wanted to hide as well.
 
Bob,
When I run first time, rows 7 onwards are hidden as expected. when
I re-run they are not unhidden as LASTROW is <7.

Or I am misunderstanding something?
 
Toppers
Code work flawlessly, after changing last header row, as it wanted to hide
as well. Thankyou for your help.
 

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

Back
Top