PC Review


Reply
Thread Tools Rate Thread

Command Button / Inputbox Questions

 
 
=?Utf-8?B?V0xNUGlsb3Q=?=
Guest
Posts: n/a
 
      19th Nov 2006
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 With Quote
 
 
 
 
Tom Ogilvy
Guest
Posts: n/a
 
      19th Nov 2006
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" <(E-Mail Removed)> wrote in message
news:42660098-0BD7-4B66-9A8D-(E-Mail Removed)...
>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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selective calculate command button & other questions. DangerPayne Microsoft Excel Misc 1 23rd Dec 2008 07:45 AM
InputBox Cancel Button A Mad Doberman Microsoft Excel Programming 1 20th Jun 2008 09:49 PM
Inputbox and cancel button Uddinj1 Microsoft Excel Programming 5 2nd Mar 2004 11:27 AM
Please help.. about InputBox command Seven Microsoft Access Form Coding 3 19th Nov 2003 09:36 AM
inputbox - cancel button fedum Microsoft Access VBA Modules 5 15th Sep 2003 08:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:47 PM.