Change part of code to an array

tatendatiffany

Board Regular
Joined
Mar 27, 2011
Messages
103
I need to change this part of my code into an array the part in bold into an array containing these 5 different tables. I can do the part of declaring the variable. But i am facing difficulty with make further changes to the rest of the code (c) part of the code. Any suggestions

Code:
[B]for c = 31 to 35
[/B]for r = 2 to 39
if cells (r,c).value <> "" then


Code:
If Cells(r, c).Value <> "" Then
                    LogStr = LogStr & "------------------------------" & vbCrLf
                    LogStr = LogStr & " Row " & r & " Col " & c & vbCrLf
                    LogStr = LogStr & "------------------------------" & vbCrLf
                    str = Cells(r, c).Value
                    LogStr = LogStr & str & vbCrLf
                    rtnVal = getrecordset(str)
                    LogStr = LogStr & rtnVal & vbCrLf
                    Cells(r, c - 5).Value = rtnVal
                End If
            Next r
        Next c
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I need to change this part of my code into an array the part in bold into an array containing these 5 different tables. I can do the part of declaring the variable. But i am facing difficulty with make further changes to the rest of the code (c) part of the code. Any suggestions

Code:
[B]for c = 31 to 35
[/B]for r = 2 to 39
if cells (r,c).value <> "" then


Code:
If Cells(r, c).Value <> "" Then
                    LogStr = LogStr & "------------------------------" & vbCrLf
                    LogStr = LogStr & " Row " & r & " Col " & c & vbCrLf
                    LogStr = LogStr & "------------------------------" & vbCrLf
                    str = Cells(r, c).Value
                    LogStr = LogStr & str & vbCrLf
                    rtnVal = getrecordset(str)
                    LogStr = LogStr & rtnVal & vbCrLf
                    Cells(r, c - 5).Value = rtnVal
                End If
            Next r
        Next c

Not completely sure but maybe something like this?

Code:
Dim x as variant

x = Array("31", "32", "33", "34", "35")

for c = Lbound(x) to Ubound(x)

for r = 2 to 39
if cells (r,c).value <> "" then
 
Upvote 0
Thank you very much for your help that seems to have done the it but now the issue i am facing is, these tables stored in array are the only part about the code that changes.
e.g. select from table where product is aa.

the part in bold changes everytime after it has run the sql query so how do i specify this in my coding???
 
Upvote 0
Thank you very much for your help that seems to have done the it but now the issue i am facing is, these tables stored in array are the only part about the code that changes.
e.g. select from table where product is aa.

the part in bold changes everytime after it has run the sql query so how do i specify this in my coding???

I don't understand what you're asking. It seems you want to assign the bold part too a variable, if it changes. Or am I missing the point all together?
 
Upvote 0
No so i have sql queries to run in 3 different "environments" and they are identical the only difference with is is the last part of each query that changes to eg.

Code:
select from file where table is AA
+ 10 more queries like that then i have to do the same thing for the other 3 tablea but the only part that is changing is:

Code:
select from file where table is BB
Code:
select from file where table is AA

so i want my code to change the tablename after completing the 10 queries then run those.

Does it make sense??
 
Upvote 0
No so i have sql queries to run in 3 different "environments" and they are identical the only difference with is is the last part of each query that changes to eg.

Code:
select from file where table is AA
+ 10 more queries like that then i have to do the same thing for the other 3 tablea but the only part that is changing is:

Code:
select from file where table is BB
Code:
select from file where table is AA

so i want my code to change the tablename after completing the 10 queries then run those.

Does it make sense??

I'm still confused? Perhaps some else can help further.
 
Upvote 0

Forum statistics

Threads
1,224,564
Messages
6,179,547
Members
452,925
Latest member
duyvmex

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