PC Review


Reply
Thread Tools Rate Thread

How do I reduce 10 Sub() into 1 Sub()?

 
 
Ayo
Guest
Posts: n/a
 
      2nd Jul 2009

I have this subroutine that I have to repeat 10 times on a worksheet:

Private Sub cmdCentralPA_Click()

Dim btnCaption As String
Application.DisplayAlerts = False
Application.ScreenUpdating = False
btnCaption = Me.cmdCentralPA.Caption
Call unhideSheets
Call getMarketdata(btnCaption)
Call hideShapes
Me.Range("A2").Select
Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub

i.e., Private Sub cmdConnecticut_Click(), Private Sub cmdLongIsland_Click(),
Private Sub cmdNewEngland_Click(), Private Sub cmdNewJersey_Click() etc.

I am looking for a code that will determine which button was click and then
run the code based on that button. Instead of repeating the same subroutine
10 times. Any ideas?
Thanks
Ayo
 
Reply With Quote
 
 
 
 
Ayo
Guest
Posts: n/a
 
      2nd Jul 2009

Thanks Per Jessen. You have given me an idea that I will look into.

"Per Jessen" wrote:

> Hi
>
> Each button has to have an underlying macro to function, but you could put
> your code in a seperat sub which is called from each button macro
> (CentralCode should in an ordinary module):
>
> Private Sub cmdCentralPA_Click()
> Call CentralCode
> End Sub
>
> Sub CentralCode()
> Dim btnCaption As String
> Application.DisplayAlerts = False
> Application.ScreenUpdating = False
> btnCaption = Me.cmdCentralPA.Caption
> Call unhideSheets
> Call getMarketdata(btnCaption)
> Call hideShapes
> Me.Range("A2").Select
> Application.ScreenUpdating = True
> Application.DisplayAlerts = True
> End Sub
>
> Hopes this helps.
> ....
> Per
>
> "Ayo" <(E-Mail Removed)> skrev i meddelelsen
> news:E95DC67B-AAB4-4D1C-8CE3-(E-Mail Removed)...
> >I have this subroutine that I have to repeat 10 times on a worksheet:
> >
> > Private Sub cmdCentralPA_Click()
> >
> > Dim btnCaption As String
> > Application.DisplayAlerts = False
> > Application.ScreenUpdating = False
> > btnCaption = Me.cmdCentralPA.Caption
> > Call unhideSheets
> > Call getMarketdata(btnCaption)
> > Call hideShapes
> > Me.Range("A2").Select
> > Application.ScreenUpdating = True
> > Application.DisplayAlerts = True
> >
> > End Sub
> >
> > i.e., Private Sub cmdConnecticut_Click(), Private Sub
> > cmdLongIsland_Click(),
> > Private Sub cmdNewEngland_Click(), Private Sub cmdNewJersey_Click() etc.
> >
> > I am looking for a code that will determine which button was click and
> > then
> > run the code based on that button. Instead of repeating the same
> > subroutine
> > 10 times. Any ideas?
> > Thanks
> > Ayo

>
>

 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      3rd Jul 2009

you may want to pass a value that indicates which button was clicked

> Private Sub cmdCentralPA_Click()
> Call CentralCode, 1
> End Sub


and
> Private Sub cmdCentralPA_Click(button as long )


"Per Jessen" <(E-Mail Removed)> wrote in message
news:ulBjUS0#(E-Mail Removed)...
> Hi
>
> Each button has to have an underlying macro to function, but you could put
> your code in a seperat sub which is called from each button macro
> (CentralCode should in an ordinary module):
>
> Private Sub cmdCentralPA_Click()
> Call CentralCode
> End Sub
>
> Sub CentralCode()
> Dim btnCaption As String
> Application.DisplayAlerts = False
> Application.ScreenUpdating = False
> btnCaption = Me.cmdCentralPA.Caption
> Call unhideSheets
> Call getMarketdata(btnCaption)
> Call hideShapes
> Me.Range("A2").Select
> Application.ScreenUpdating = True
> Application.DisplayAlerts = True
> End Sub
>
> Hopes this helps.
> ...
> Per
>
> "Ayo" <(E-Mail Removed)> skrev i meddelelsen
> news:E95DC67B-AAB4-4D1C-8CE3-(E-Mail Removed)...
>>I have this subroutine that I have to repeat 10 times on a worksheet:
>>
>> Private Sub cmdCentralPA_Click()
>>
>> Dim btnCaption As String
>> Application.DisplayAlerts = False
>> Application.ScreenUpdating = False
>> btnCaption = Me.cmdCentralPA.Caption
>> Call unhideSheets
>> Call getMarketdata(btnCaption)
>> Call hideShapes
>> Me.Range("A2").Select
>> Application.ScreenUpdating = True
>> Application.DisplayAlerts = True
>>
>> End Sub
>>
>> i.e., Private Sub cmdConnecticut_Click(), Private Sub
>> cmdLongIsland_Click(),
>> Private Sub cmdNewEngland_Click(), Private Sub cmdNewJersey_Click() etc.
>>
>> I am looking for a code that will determine which button was click and
>> then
>> run the code based on that button. Instead of repeating the same
>> subroutine
>> 10 times. Any ideas?
>> Thanks
>> Ayo

>

 
Reply With Quote
 
norie
Guest
Posts: n/a
 
      3rd Jul 2009
Perhaps Application.Caller might help.


On Jul 2, 7:29*pm, Ayo <A...@discussions.microsoft.com> wrote:
> I have this subroutine that I have to repeat 10 times on a worksheet:
>
> Private Sub cmdCentralPA_Click()
>
> Dim btnCaption As String
> Application.DisplayAlerts = False
> Application.ScreenUpdating = False
> btnCaption = Me.cmdCentralPA.Caption
> Call unhideSheets
> Call getMarketdata(btnCaption)
> Call hideShapes
> Me.Range("A2").Select
> Application.ScreenUpdating = True
> Application.DisplayAlerts = True
>
> End Sub
>
> i.e., Private Sub cmdConnecticut_Click(), Private Sub cmdLongIsland_Click(),
> Private Sub cmdNewEngland_Click(), Private Sub cmdNewJersey_Click() etc.
>
> I am looking for a code that will determine which button was click and then
> run the code based on that button. Instead of repeating the same subroutine
> 10 times. Any ideas?
> *Thanks
> * *Ayo


 
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
how to reduce word for example date is 1th i want reduce th your answer Microsoft Word New Users 1 31st Jul 2008 06:51 PM
How do I reduce the MB size of pictures to reduce size of file ? =?Utf-8?B?bWFkcnVzc2lhbjE5NjA=?= Microsoft Powerpoint 1 10th Mar 2005 08:17 PM
Reduce EXE *ProteanThread* Freeware 0 8th Jul 2004 10:21 PM
Can it be done? Reduce width of slide show on a page or reduce number of thumbnails displayed at the top? =?Utf-8?B?YWxpd2Vi?= Microsoft Frontpage 4 28th Apr 2004 05:51 PM
Reduce width of photo gallery or reduce number of thumbs displayed =?Utf-8?B?YWxpd2Vi?= Microsoft Frontpage 3 28th Apr 2004 03:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:21 PM.