By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,377 Members | 493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,377 IT Pros & Developers. It's quick & easy.

MS EXCEL Code will not work with "Active Sheets" only the current sheet.

P: 231
I have an excel sheet with 5 worksheets inside it (5 tabs). I have 3 columns that I want to hide unless their NTID is asnoble. If they arn't me then hide the 3 coluns on all the sheets. The way it happens now is right when it comes up, the code works on the first sheet. Then when you click another sheet it stops working. I have this code on all the tabs in code, also a module. It just doesn't work whenever you click another sheet.

I put my name in their as an example :)
Please help

Here is my code:
Expand|Select|Wrap|Line Numbers
  1. Sub Auto_Open()
  2. '
  3. ' Auto_Open Macro
  4. ' Macro recorded 6/4/2010 by Joseph D. Marcrum, III
  5. '
  7. '
  9. If Environ("username") <> "asnoble" Then
  10.     Columns("I").Hidden = True
  11.     Columns("J").Hidden = True
  12.     Columns("K").Hidden = True
  13. End If
  15. End Sub
Jun 4 '10 #1
Share this Question
Share on Google+
1 Reply

Expert 5K+
P: 8,741
Expand|Select|Wrap|Line Numbers
  1. Dim sht As Excel.Worksheet
  3. If Environ("username") <> "asnoble" Then
  4.   For Each sht In ActiveWorkbook.Worksheets
  5.     sht.Columns("I:K").Hidden = True
  6.   Next
  7. End If
Jun 7 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.