tatendatiffany
Board Regular
- Joined
- Mar 27, 2011
- Messages
- 103
Could someone please i have to create this vba that runs through different tables and return the result on an sql sheet. I have done some of it but i am stuck on a part where it loops through the tables on a dropdown list: and combining this with sql is proving difficult. this is what i have done so far:
Public Sub LoopTable()
Dim TABLES_S As range
For Each TABLES_S In Worksheets("Sheet 1").range("C2:C39").Cells ' runs through the column of table names
If TABLES_S = "" Then
End If
Next TABLES_S
End Sub
Public Sub LoopColumn()
Dim TableClmn As range
Dim Index As Worksheet
Set Index = ActiveSheet
Index.Activate
For Each TableClmn In Worksheets("Index").range("W2:W39").Cells 'runs through the column of column names
If TableClmn = "" Then
End If
Next TableClmn
End Sub
Public Sub Retrieve()
Dim j As Long
Dim SQL1 As String
Dim TABLES_S As range
Dim TableClmn As range
Dim rst As Recordset
For j = 1 To 38
Cells(j + 1, 24).Value = j 'column were value will be placed
Dim i As Long
With Sheets("Index")
For i = 1 To .range("TABLES_S").Rows.count
SQL1 = "SELECT FROM " & .range("TABLES_S")(i, 1) & .range("TableClmn")(i, 1) & Sheets("Element").range("GESTATUS")(i, 1)
Debug.Print SQL1 ' loop through the ranges in excel sheet
Next i
Dim rngCell As range
For Each rngCell In range("GESTATUS")
Call execSQL(SQL1, "Get Element", "GEREGS")
Next Rng
Public Sub LoopTable()
Dim TABLES_S As range
For Each TABLES_S In Worksheets("Sheet 1").range("C2:C39").Cells ' runs through the column of table names
If TABLES_S = "" Then
End If
Next TABLES_S
End Sub
Public Sub LoopColumn()
Dim TableClmn As range
Dim Index As Worksheet
Set Index = ActiveSheet
Index.Activate
For Each TableClmn In Worksheets("Index").range("W2:W39").Cells 'runs through the column of column names
If TableClmn = "" Then
End If
Next TableClmn
End Sub
Public Sub Retrieve()
Dim j As Long
Dim SQL1 As String
Dim TABLES_S As range
Dim TableClmn As range
Dim rst As Recordset
For j = 1 To 38
Cells(j + 1, 24).Value = j 'column were value will be placed
Dim i As Long
With Sheets("Index")
For i = 1 To .range("TABLES_S").Rows.count
SQL1 = "SELECT FROM " & .range("TABLES_S")(i, 1) & .range("TableClmn")(i, 1) & Sheets("Element").range("GESTATUS")(i, 1)
Debug.Print SQL1 ' loop through the ranges in excel sheet
Next i
Dim rngCell As range
For Each rngCell In range("GESTATUS")
Call execSQL(SQL1, "Get Element", "GEREGS")
Next Rng