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

A

Ayo

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top