![]() |
What am I missing here...?
why doesn't this code work on a command button, but works as sub? ---------------------------------- Fails at Range("A1").Select Private Sub CommandButton1_Click() ' Application.ScreenUpdating = False ' SHOWS ONLY SHEETS "A" For Each sh In Sheets sh.Visible = True Next sh Sheets(Array("A 01", "A 02", "B 01", "B 02")).Select ActiveWindow.SelectedSheets.Visible = False Sheets("A 01").Visible = True Sheets("A 02").Visible = True Sheets("A 01").Select Range("A1").Select ' Application.ScreenUpdating = True End Sub --------------------------------------------- Yet this works via MacroRun Sub Macro1() For Each sh In Sheets sh.Visible = True Next sh Sheets(Array("A 01", "A 02", "B 01", "B 02")).Select ActiveWindow.SelectedSheets.Visible = False Sheets("A 01").Visible = True Sheets("A 02").Visible = True Sheets("A 01").Select Range("A1").Select End Sub ---------------------------------------------- This selects cell A1 on Sheet "A 01" Does this have something to do with the command button still be selected? How to get around this? Thanks for your input. Bruce -- swatsp0p ------------------------------------------------------------------------ swatsp0p's Profile: http://www.excelforum.com/member.php...o&userid=15101 View this thread: http://www.excelforum.com/showthread...hreadid=345566 |
What am I missing here...?
See answer to second posting.
-- Regards, Tom Ogilvy "swatsp0p" wrote in message ... why doesn't this code work on a command button, but works as sub? ---------------------------------- Fails at Range("A1").Select Private Sub CommandButton1_Click() ' Application.ScreenUpdating = False ' SHOWS ONLY SHEETS "A" For Each sh In Sheets sh.Visible = True Next sh Sheets(Array("A 01", "A 02", "B 01", "B 02")).Select ActiveWindow.SelectedSheets.Visible = False Sheets("A 01").Visible = True Sheets("A 02").Visible = True Sheets("A 01").Select Range("A1").Select ' Application.ScreenUpdating = True End Sub --------------------------------------------- Yet this works via MacroRun Sub Macro1() For Each sh In Sheets sh.Visible = True Next sh Sheets(Array("A 01", "A 02", "B 01", "B 02")).Select ActiveWindow.SelectedSheets.Visible = False Sheets("A 01").Visible = True Sheets("A 02").Visible = True Sheets("A 01").Select Range("A1").Select End Sub ---------------------------------------------- This selects cell A1 on Sheet "A 01" Does this have something to do with the command button still be selected? How to get around this? Thanks for your input. Bruce -- swatsp0p ------------------------------------------------------------------------ swatsp0p's Profile: http://www.excelforum.com/member.php...o&userid=15101 View this thread: http://www.excelforum.com/showthread...hreadid=345566 |
All times are GMT +1. The time now is 11:20 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com