Unhide Next 2 rows with macro button

MagalieD

New Member
Joined
Oct 28, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. MacOS
Hi,
I'm working on a Schedule Sheet where when you push a Macro Button, the employee information enters the schedule automatically. Where I have a problem, is that I want the rows hidden before entering the informations in the schedule.

Exemple:
The employees infos are in column A and B on 2 rows. If before adding a new employee I have 5 employees, my schedule will have 10 rows. Now, I want that when a Manager enters the new informations and click a the button "Add Employee" 2 rows are added or unhidden and the informations are already in the schedule, ready to add their Shifts.

I hope it's clear,
Thanks for the help.
 

Some videos you may like

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
47,483
Office Version
  1. 365
Platform
  1. Windows
Welcome to the MrExcel board!

See if this is any use. I assume that you have at least 1 heading row and then some employee data rows.
Hide some rows below that & use this code to unhide two at a time.

VBA Code:
Sub Unhide2rows()
  With Columns("A").SpecialCells(xlVisible).Areas(1)
    If .Rows.Count < Columns("A").Rows.Count - 1 Then .Resize(.Rows.Count + 2).EntireRow.Hidden = False
  End With
End Sub
 
Solution

MagalieD

New Member
Joined
Oct 28, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. MacOS
Thanks, it works! I just needed to format my schedule as a table and it works perfectly! Thank you!
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
47,483
Office Version
  1. 365
Platform
  1. Windows
Having a formal table is fine (& often a very good idea) however you shouldn't have needed a formal table just to make my code work.
Anyway, glad it helped & thanks for the follow-up. :)
 

Watch MrExcel Video

Forum statistics

Threads
1,118,272
Messages
5,571,243
Members
412,373
Latest member
HelpPls21NZ
Top