No errors on loop

tatendatiffany

Board Regular
Joined
Mar 27, 2011
Messages
103
my loop doesn't seem to be doing anything, its not giving me any error of the problems within the loop but is is not doing anything could someone enlighten me as to why. also i want to add another code to tell excel where to display the results from each run how do i do that



Code:
Public Sub LoopQueries()
Dim SQL1 As Variant
Dim c As Range
SQL1 = ThisWorkbook.Worksheets("Index").Range("Environ4")
For Each c In ThisWorkbook.Worksheets("Index").Range("Environ4")
    c.Offset(, 2).Value = c.Value
Next c

End
' THIS IS CONNECTION TO AMA4 RUNNING THROUGH ENTIRE COLUMN

Dim SQL2 As Variant
Dim d As Range
SQL2 = ThisWorkbook.Worksheets("Index").Range("Environ1")
For Each d In ThisWorkbook.Worksheets("Index").Range("Environ1")
d.Offset(, 2).Value = d.Value
Next d

End
'THIS CONNECTS TO AM1 AND IS RUNNING THROUGHOUT THE COLUMN
Dim SQL3 As Variant
Dim e As Range
SQL3 = ThisWorkbook.Worksheets("Index").Range("Environ3")
For Each e In ThisWorkbook.Worksheets("Index").Range("Environ3")
e.Offset(, 2).Value = e.Value
Next e

End
' THIS IS CONNECTION TO AMA3 RUNNING THROUGH ENTIRE COLUMN
Dim SQL4 As Variant
Dim f As Range
SQL3 = ThisWorkbook.Worksheets("Index").Range("Environ5")
For Each f In ThisWorkbook.Worksheets("Index").Range("Environ5")
f.Offset(, 2).Value = f.Value
Next f

End


' THIS IS CONNECTION TO AM5 RUNNING THE ENTIRE COLUMN

Dim SQL5 As Variant
Dim g As Range
SQL3 = ThisWorkbook.Worksheets("Index").Range("Environ7")
For Each g In ThisWorkbook.Worksheets("Index").Range("Environ7")
g.Offset(, 2).Value = g.Value
Next g
End
End Sub
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
You might stand more chance of getting an answer if you explain what you're trying to do.

It would suggest that you're trying to run server queries, but in reality, all your code does is copy the values in each of the 5 named ranges, in the order they appear in the code, 2 columns to the right.
 
Upvote 0
Sorry for not much context, well i am trying to run sql queries in the columns i have named as ranges "environ4" each column ranges from e.g. AC2 to AC39 and i want the result to be displayed in another cell e.g. A.
So how do you suggest i change the loop to make it execute instead of copy??
 
Upvote 0

Forum statistics

Threads
1,224,504
Messages
6,179,142
Members
452,892
Latest member
JUSTOUTOFMYREACH

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