Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default How do I reduce 10 Sub() into 1 Sub()?


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
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ayo Ayo is offline
external usenet poster
 
Posts: 489
Default How do I reduce 10 Sub() into 1 Sub()?


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" skrev i meddelelsen
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default How do I reduce 10 Sub() into 1 Sub()?


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" wrote in message
...
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" skrev i meddelelsen
...
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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default How do I reduce 10 Sub() into 1 Sub()?

Perhaps Application.Caller might help.


On Jul 2, 7:29*pm, Ayo 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
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
How do I reduce 10 Sub() into 1 Sub()? Per Jessen Excel Programming 0 July 2nd 09 07:40 PM
Can I reduce (101.25) to only what's *right* of decimal? (25) jay45940 Excel Worksheet Functions 2 September 18th 08 08:10 PM
Reduce filesize Robin Excel Discussion (Misc queries) 3 September 27th 07 03:08 PM
Reduce Flashing Zone Excel Programming 5 August 29th 06 06:06 AM
How to reduce table? ilyaz New Users to Excel 9 August 9th 06 12:06 AM


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