Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default 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
--
The older I get, the better I used to be.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default What am I missing here....?

Bruce-

I can't explain why the sub code works while the button code does not, but
if you replace "Range("A1").Select" with "Activesheet.Range("A1").Select"
your button code will work.

-Stan Shoemaker
Palo Alto, CA

"swatsp0p" wrote:

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
--
The older I get, the better I used to be.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default What am I missing here....?

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
Sheets("A 01").(Range("A1").Select
' Application.ScreenUpdating = True

End Sub

an unqualified range refers to the sheet containing the code when housed in
a sheet module. Since this isn't the activesheet - it can not be selected.
Specifying which sheet by qualifying it solves the problem.

--
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
--
The older I get, the better I used to be.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default What am I missing here....?

Thanks to stanshoe and Tom O. for their help. I was missing the part that
the commandbutton is looking at the sheet housing the code. Simply selecting
the sheet didn't work. Now it works as desired.

Thanks again.

"Tom Ogilvy" wrote:

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
Sheets("A 01").(Range("A1").Select
' Application.ScreenUpdating = True

End Sub

an unqualified range refers to the sheet containing the code when housed in
a sheet module. Since this isn't the activesheet - it can not be selected.
Specifying which sheet by qualifying it solves the problem.

--
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
--
The older I get, the better I used to be.




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Missing MB Gotroots Excel Discussion (Misc queries) 1 December 2nd 09 02:21 PM
#Missing Shirley Excel Worksheet Functions 1 August 28th 08 10:22 PM
Something Missing Looping through Excel Worksheet Functions 4 December 18th 07 02:42 PM
Toolbars Missing, And option to Add Missing SmeetaG Excel Discussion (Misc queries) 3 October 19th 05 11:43 AM
Missing row Kim Excel Discussion (Misc queries) 4 August 19th 05 12:47 AM


All times are GMT +1. The time now is 08:59 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"