looping to through rows

C

carey.declan

i am writing a code to output data from a database called PHD to a
sheet called PI_PHD. when you select a range of tags to output from
the values are output across the columns instead of being output down
in rows. this cannot be helped. the way around is to repeat the
database call for each different tag. the code is as follows:

Sub GetData()

Dim StartTime, EndTime, TimeIncrement, TagList, TEMP1, TEMP1_1, TEMP2,
Dim TEMP3

StartTime = "PI_PHD!$B$1,"
EndTime = "PI_PHD!$B$2,"
TimeIncrement = "PI_PHD!$B$3"
TagList = "PI_PHD!$A$7:$A$7,"
TEMP1 = "=PHDGetData(""PHD_HOST"","
'TEMP1_1 = "*=PHDGetData(""PHD_HOST"","
TEMP2 = """"", ""Snapshot"","
TEMP3 = ",0, ""After"", UNI_RET_VALUE, UNI_PRES_MERGED)"
Sheets("PI_PHD").Select
Range("b7") = TEMP1 & TagList & StartTime & EndTime & TEMP2 &
TimeIncrement & TEMP3

End Sub

essentially i want to cycle tag list through A8, A9, A10 etc to the
end of data

please help!
 
J

Joel

I think this is what you are looking for

Sub GetData()

Dim StartTime, EndTime, TimeIncrement, TagList
Dim TEMP1, TEMP1_1, TEMP2, TEMP3

StartTime = "PI_PHD!$B$1,"
EndTime = "PI_PHD!$B$2,"
TimeIncrement = "PI_PHD!$B$3"
TEMP1 = "=PHDGetData(""PHD_HOST"","
'TEMP1_1 = "*=PHDGetData(""PHD_HOST"","
TEMP2 = """"", ""Snapshot"","
TEMP3 = ",0, ""After"", UNI_RET_VALUE, UNI_PRES_MERGED)"

Sheets("PI_PHD").Select
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
For RowCount = 7 To LastRow

TagList = "PI_PHD!$A$" & RowCount & ":$A$" & _
RowCount & ","
Range("b" & RowCount) = TEMP1 & TagList & StartTime & EndTime & _
TEMP2 & TimeIncrement & TEMP3
Next RowCount
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top