Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Naming vba Buttons

In very basic terms I have a spreadhseet with three sheets... I want a
user to be prompted to select 1 of the three sheets and each of the
three sheets will then require different code... I have the different
code but do not know how to get the suer to
select one of the three sheets...

My simple idea of code is thus...

Sub test()
result = MsgBox("Select Sheet", vbSheet1Sheet2Sheet3, "Banking")
If result = vbSheet1 Then
GoTo label1
Else
If result = vbSheet2 Then
GoTo label2
Else
If result = vbSheet3 Then
GoTo label3
End If
End If
End If

label1:
'Some code here
label2:
'Some code here
label3:
'Some code here

End Sub

I've worked out that it's not as simple as I would like it to be... but
can't use logic to work out the other way around... any ideas?

Many many thanks to you fine people...

Will

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Naming vba Buttons

Why not get them to activate the sheet and use worksheet activate code to
run?

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Select Case Sh.Name
Case "Sheet1":
'sheet 1 code
Case "Sheet2":
'sheet 2 code
Case "Sheet3":
'sheet 3 code
End Select
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code


--

HTH

RP
(remove nothere from the email address if mailing direct)


"solomon_monkey" wrote in message
oups.com...
In very basic terms I have a spreadhseet with three sheets... I want a
user to be prompted to select 1 of the three sheets and each of the
three sheets will then require different code... I have the different
code but do not know how to get the suer to
select one of the three sheets...

My simple idea of code is thus...

Sub test()
result = MsgBox("Select Sheet", vbSheet1Sheet2Sheet3, "Banking")
If result = vbSheet1 Then
GoTo label1
Else
If result = vbSheet2 Then
GoTo label2
Else
If result = vbSheet3 Then
GoTo label3
End If
End If
End If

label1:
'Some code here
label2:
'Some code here
label3:
'Some code here

End Sub

I've worked out that it's not as simple as I would like it to be... but
can't use logic to work out the other way around... any ideas?

Many many thanks to you fine people...

Will



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Naming vba Buttons

Nice idea but the code need not run every time the sheet is selected.

How do you set it up so when the spreadsheet is selected it runs the
code?

What other solution would you suggest?

Thanks again...

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Naming vba Buttons

Maybe

Private Sub Workbook_Open()
Dim ans
ans=MsgBox("Supply a value from this list" & vbCrLf & _
"Sheet1, Sheet2, Sheet3")
Select Case ans
Case "Sheet1":
'sheet 1 code
Case "Sheet2":
'sheet 2 code
Case "Sheet3":
'sheet 3 code
End Select
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code

--

HTH

RP
(remove nothere from the email address if mailing direct)


"solomon_monkey" wrote in message
ups.com...
Nice idea but the code need not run every time the sheet is selected.

How do you set it up so when the spreadsheet is selected it runs the
code?

What other solution would you suggest?

Thanks again...



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
Option Buttons/Radio Buttons John Calder New Users to Excel 7 May 16th 08 03:51 AM
have toggle buttons but everytime print preview buttons move TinSandhu Excel Discussion (Misc queries) 1 October 11th 06 02:57 PM
Naming of MsgBox Buttons Chuckles123[_6_] Excel Programming 1 October 3rd 04 10:42 PM
Naming of MsgBox Buttons Ivan F Moala[_14_] Excel Programming 2 October 3rd 04 12:54 PM
Naming buttons in Userform on the fly Richard Excel Programming 1 May 17th 04 08:57 AM


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