How can I run multiple subs from a single page?

Rubicon9

New Member
Joined
Jun 17, 2016
Messages
1
Hello all,
I'm trying to run all my worksheets from the Sheet1 (Report) with using just a button.


Currently I have to go to each sheet and run them one by one. I'd like to have this automated.


here is my code that I have in all 72 worksheets (I have this type of format "But different Ranges" in all 72 pages).
WorkSheet1 name is "Report" and does not have any code in it.

Code:
Sub ADOExcelSQLServer()
     
    Dim Cn As ADODB.Connection
    Dim Server_Name As String
    Dim Database_Name As String
    Dim User_ID As String
    Dim Password As String
    Dim SQLStr As String
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
     
    Server_Name = "xxxx"
    Database_Name = "xxxx"
    User_ID = "xxxx"
    Password = "*xxxx"
    ' Pulling Data for ?
    SQLStr = "Sxxxx"
    
     
    Set Cn = New ADODB.Connection
    Cn.Open "Driver={SQL Server};Server=" & Server_Name & ";Database=" & Database_Name & _
    ";Uid=" & User_ID & ";Pwd=" & Password & ";"
     
    rs.Open SQLStr, Cn, adOpenStatic
     ' Dump to spreadsheet
    With Worksheets("Kansas City").Range("a3:z500") ' Enter your sheet name and range here
        .ClearContents
        .CopyFromRecordset rs
    End With
     ' clean up
    rs.Close
    Set rs = Nothing
    Cn.Close
    Set Cn = Nothing
    
    Dim ws As Worksheet
    For Each ws In Worksheets
        With ws.Range("A" & Rows.Count).End(xlUp).Offset(2, 7)
            .NumberFormat = "General"
            .Value = .Row - 4
            Application.ScreenUpdating = False
            Worksheets("Report").Range("D134").Value = Worksheets("Kansas City").Range("H9").Value
            Application.ScreenUpdating = True


        End With
    Next
   
 End Sub


Is there a way to do this?

Thank you,
Rubi
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
You have to put your code at Modules and not in sheet, in sheet then you can call the Sub
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,363
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top