I need a macro to run every time I swtich to a particular worksheet.

Hello,

I have a script written that hides blank cells to generate a nice looking invoice, the only problem is currently I have to press a button to run it. What I would like to do is have the macro execute every time I open up the sheet 'Invoice'. Invoice is made up from data in other sheets. If someone could help me with this it would be greatly appreciated. Thanks!
thefuossAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zorvek (Kevin Jones)ConsultantCommented:
Add the following code to the worksheet's code module:

Private Sub Worksheet_Activate()
   YourMacro
End Sub

To add VBA code to a worksheet module in an Excel workbook, right-click on the worksheet tab at the bottom of the window and select View Code. Paste the code into the document window that appears. Press ALT+F11 to return to the Excel workbook. To find a worksheet module when already in the VBE, press CTRL+R to open the VBE project explorer. Find the worksheet module in which the code will be placed - each worksheet module is pre-assigned a name such as "Sheet1 (Sheet1)" where the name inside the parenthesis is the worksheet's tab name. Double-click the desired module and paste the code into the document window that appears. Press ALT+F11 to return to the Excel workbook.

Kevin

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
thefuossAuthor Commented:
I love you!
thefuossAuthor Commented:
Not to be gay or anything... haha
zorvek (Kevin Jones)ConsultantCommented:
:-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.