Unhide Next 2 rows with macro button

MagalieD

New Member
Joined
Oct 28, 2020
Messages
5
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.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
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
 
Upvote 0
Solution
Thanks, it works! I just needed to format my schedule as a table and it works perfectly! Thank you!
 
Upvote 0
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. :)
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,876
Members
449,056
Latest member
ruhulaminappu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top