Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 470
Default Command Button / Inputbox Questions

I have a workbook that contains several sheets. I am aware that one can
click on the sheettab to change sheets. However, when I was wanting to learn
VBA, I played around with creating command buttons on each sheet that would
switch to the corresponding sheet when one was clicked. I also learned that
each commandbutton was sheet specific, ie everytime a commandbutton was
created, it was created with reference to Sheet1, 2, 3, etc. FYI: The names
of the different sheets in my workbook are "STATS", "PCEMS", "PAS", "2005",
"2006", "2007".

Now I am trying to consolidate in order to try & learn different ways to do
the same thing:

1) Can a command button be created that works across the board for the whole
workbook? The idea I had, especially for the different years, is to have a
commandbutton w/ caption "YEAR". When it is clicked an Inputbox would pop up
asking for the year you wish to view, then switch according when OK clicked.
I don't want to have to write the code for each sheet. I can handle the code
for the Inputbox, just need to know about the first part of question.

2) As I write this question, different options are already flowing through
my little brain. Can in Inputbox contain a listbox or combo box? If I have
a command button that simply says "Change Screens" and then have "something"
pop up that allows the user to choose which screen to change to. Can this be
done, first of all, and secondly, can it only be written once with each
commandbutton on each sheet referencing the same code?

Thanks,
Les
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Command Button / Inputbox Questions

Use buttons from the forms toolbar instead. You can assign a single macro
to all the buttons.

Public Btn_click() ' you can use any name for the macro
Dim ans as string, sh as Worksheet
ans = InputBox("Enter Year")
on error resume next
set sh = worksheets(ans)
On error goto 0
if not sh is nothing then
sh.Activate
else
msgbox "Bad answer"
end if
end Sub

If you want dropdowns and so forth, then you will need to create a userform
(or dialogsheet. )

--
Regards,
Tom Ogilvy



"WLMPilot" wrote in message
...
I have a workbook that contains several sheets. I am aware that one can
click on the sheettab to change sheets. However, when I was wanting to
learn
VBA, I played around with creating command buttons on each sheet that
would
switch to the corresponding sheet when one was clicked. I also learned
that
each commandbutton was sheet specific, ie everytime a commandbutton was
created, it was created with reference to Sheet1, 2, 3, etc. FYI: The
names
of the different sheets in my workbook are "STATS", "PCEMS", "PAS",
"2005",
"2006", "2007".

Now I am trying to consolidate in order to try & learn different ways to
do
the same thing:

1) Can a command button be created that works across the board for the
whole
workbook? The idea I had, especially for the different years, is to have
a
commandbutton w/ caption "YEAR". When it is clicked an Inputbox would pop
up
asking for the year you wish to view, then switch according when OK
clicked.
I don't want to have to write the code for each sheet. I can handle the
code
for the Inputbox, just need to know about the first part of question.

2) As I write this question, different options are already flowing through
my little brain. Can in Inputbox contain a listbox or combo box? If I
have
a command button that simply says "Change Screens" and then have
"something"
pop up that allows the user to choose which screen to change to. Can this
be
done, first of all, and secondly, can it only be written once with each
commandbutton on each sheet referencing the same code?

Thanks,
Les



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
Selective calculate command button & other questions. DangerPayne Excel Discussion (Misc queries) 1 December 23rd 08 07:45 AM
VB's Command Button vs Form's Command Button Ronald Dodge Excel Programming 3 May 24th 06 02:23 PM
InputBox - cancel button Greg Billinge Excel Programming 4 October 11th 04 06:45 PM
Inputbox and cancel button Uddinj1 Excel Programming 5 March 2nd 04 11:27 AM
Cancel button in Inputbox method MiRa Excel Programming 2 November 14th 03 01:04 PM


All times are GMT +1. The time now is 01:54 PM.

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

About Us

"It's about Microsoft Excel"