Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Command buttons and code - help!!

Hi everyone,

OK, so i have a Worksheet with five command buttons on, i.e. RunASH_Mon,
RunASH_Tues etc etc

I call the following code on each of the buttons (there is actually 10
worksheets all with five buttons with the same names), and this works fine
but I want to be able to pass the command button name, as I have with the
worksheet name, so that I only have one sub routine instead of five.


Sub RunASHMon(SheetN As String)

Application.ScreenUpdating = False

Sheets("Data").Activate
ActiveSheet.Range("A1:D119").Copy
Sheets(SheetN).Activate
ActiveSheet.Range("A6").Select
ActiveSheet.Paste

Application.ScreenUpdating = True

End Sub

Any ideas how I would do this, maybe with as IF....THEN statement? Basically
I want it to say,

IF (the command button name is RunASH_Mon and has been clicked) THEN
ActiveSheet.Range ("A6").Select.Paste
IF (RunASH_Tues has been clicked) THEN
ActiveSheet.Range("G6").Select.Paste
etc etc

Any help would be greatly appreciated

Cheers
Lindsey M
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Command buttons and code - help!!

Lindsey,

If you are using buttons from the Forms toolbar
then something like this...

'--------------------------------------------------
Sub ButtonTest()
Dim strName As String
strName = Application.Caller

Select Case strName
Case "Button 1"
ActiveSheet.Range("A6").Select
Case "Button 2"
ActiveSheet.Range("B10").Paste
Case "Button 3"
ActiveSheet.Range("C15").Paste
Case "Button 4"
ActiveSheet.Range("D20").Paste
Case "Button 5"
ActiveSheet.Range("E25").Paste
End Select

End Sub
'-------------------------------------------------

Regards,
Jim Cone
San Francisco, USA



"Lindsey M" wrote in message
...
Hi everyone,

OK, so i have a Worksheet with five command buttons on, i.e. RunASH_Mon,
RunASH_Tues etc etc

I call the following code on each of the buttons (there is actually 10
worksheets all with five buttons with the same names), and this works fine
but I want to be able to pass the command button name, as I have with the
worksheet name, so that I only have one sub routine instead of five.
Sub RunASHMon(SheetN As String)
Application.ScreenUpdating = False
Sheets("Data").Activate
ActiveSheet.Range("A1:D119").Copy
Sheets(SheetN).Activate
ActiveSheet.Range("A6").Select
ActiveSheet.Paste
Application.ScreenUpdating = True
End Sub

Any ideas how I would do this, maybe with as IF....THEN statement? Basically
I want it to say,

IF (the command button name is RunASH_Mon and has been clicked) THEN
ActiveSheet.Range ("A6").Select.Paste
IF (RunASH_Tues has been clicked) THEN
ActiveSheet.Range("G6").Select.Paste
etc etc
Any help would be greatly appreciated
Cheers
Lindsey M

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
command code ( GOTO command) in formula calan New Users to Excel 1 June 11th 09 09:44 AM
Code for Command Buttons Ayman Excel Discussion (Misc queries) 1 November 3rd 08 08:37 PM
Command buttons etc TimO Excel Programming 1 July 28th 04 06:55 AM
Command buttons Craig[_8_] Excel Programming 4 February 8th 04 03:56 AM
Control Buttons vs. Command Buttons Robert Gibson Excel Programming 1 October 13th 03 04:33 PM


All times are GMT +1. The time now is 09:16 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"