Help: Loop through excel sheet

tatendatiffany

Board Regular
Joined
Mar 27, 2011
Messages
103
I have a loop that runs through excel sheet column containing sql queries and display them in the next sheet. But i also want the loop after completing this column to run sql queries in another column and display results on sheet. This is what i have done so far :

Code:
Public Sub LoopQueries()
Dim i As Long
Dim MFcnn As New ADODB.Connection
Set MFcnn = New ADODB.Connection
With MFcnn
.Provider = "IBMDADB2.DB2COPY2"
.Mode = adReadWrite
.ConnectionString = "Password=" & password & ";Persist Security Info=True;User ID=" & username & ";Data Source=" & DatabaseEnv & ";Mode=ReadWrite;"
'.Open
Dim rsMFcnn As ADODB.Recordset
Set rsMFcnn = New ADODB.Recordset
Dim SQL As String
SQL = Sheet1.Range("AE2")
With rsMFcnn
.Open SQL
Sheet1.Range("AC2").CopyFromRecordset rsMFcnn
.Close
End With
cnMFcnn.Close
Set rsMFcnn = Nothing
Set cnMFcnn = Nothing
For j = 1 To 2
If (Sheet1.Cells(i, 1) = "") Then
j = 2
Else
j = 1
i = i + 1
End If
Next
 
End With
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Forum statistics

Threads
1,224,503
Messages
6,179,134
Members
452,890
Latest member
Nikhil Ramesh

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