Command Button question
Have each button call the exact same routine, say "Giselle"
Each button has a name, like Button 1, Button 2, etc. You can see which
button was clicked by Application.Caller:
Sub Giselle()
Select Case Application.Caller
Case "Button 1"
TheRange = "A1:A5"
Common
Case "Button 2"
TheRange = "G4:G88"
Common
Case "Button 3"
TheRange = "N3:Z3"
Common
'....etc
End Select
End Giselle
Sub Common(Rg as String)
Set RangeToWorkOn = Range(Rg)
'...now work with RangeToWorkOn
End Sub
instead of putting 5 buttons on each sheet, why not use a new commandbar
with 5 controls (each a commandbutton) - that way it'd always be visible, no
matter which sheet you're on.
Bob Umlas
Excel MVP
"Giselle" wrote in message
...
Greetings
I'm fairly new at XL programming and I need a bit of help.
I have a worksheet that contains, among other things, 5 command Buttons.
Part 1: The 40+ lines of code in each button is identical, except for
some range references. ( eg cmdA, cmdB ...etc refer to Range(D5:E25),
Range(J5:K25) ...etc). Can someone suggest how I can only enter the
code
once to save space and have each button run the code with its own
appropriate ranges.
Part 2: There are eventually going to be 24 worksheets like the one
above, each having these same 5 buttons. On each worksheet, cmdA does the
exactly same thing. (same for cmdB, etc). Ideally, I'd like the code to
be
usable by ALL buttons (24x5=120) in the workbook. I'm not sure how to
proceed.
Thank you very much for any help
Giselle
|