![]() |
Code for button to hide/unhide rows
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. -- Regards |
Code for button to hide/unhide rows
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 "Chris" wrote: 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. -- Regards |
Code for button to hide/unhide rows
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) "Toppers" wrote in message ... 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 "Chris" wrote: 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. -- Regards |
Code for button to hide/unhide rows
Thanks both work. Just had to assign header as it wanted to hide as well.
-- Regards "Bob Phillips" wrote: 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) "Toppers" wrote in message ... 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 "Chris" wrote: 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. -- Regards |
Code for button to hide/unhide rows
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? "Bob Phillips" wrote: 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) "Toppers" wrote in message ... 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 "Chris" wrote: 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. -- Regards |
Code for button to hide/unhide rows
Toppers
Code work flawlessly, after changing last header row, as it wanted to hide as well. Thankyou for your help. -- Regards Chris "Toppers" wrote: 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 "Chris" wrote: 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. -- Regards |
All times are GMT +1. The time now is 08:00 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com