Skip to main content

Good day everyone,

 

I am trying to write a script to write information to excel, which I currently have, but I would like it to know to add information to the next row.

For example: If i'm writing information to A1, the next time it writes it, I would like it to go to A2.

I would like to accomplish this without staticly writing A1, A2, A3, etc.

Is there a way to this? Such as A1 1 or something like that?

 

Thank you.


#Rumba

Good day everyone,

 

I am trying to write a script to write information to excel, which I currently have, but I would like it to know to add information to the next row.

For example: If i'm writing information to A1, the next time it writes it, I would like it to go to A2.

I would like to accomplish this without staticly writing A1, A2, A3, etc.

Is there a way to this? Such as A1 1 or something like that?

 

Thank you.


#Rumba

Hi,
the Excel object let you address any cell by using ActiveWorkbook.Sheets("Sheet1").Cells(row, col)

Sub mytest()
Set cell = ActiveWorkbook.Sheets("Sheet1").Cells(2, 1)     ' writes to cell A2
cell.Value = "RUMBA"
End Sub

In case you want to construct the Range yourself see below sample code:

Sub Main

' cell (row & count)

Dim cell As String
Dim col As String
Dim count As Integer

col = "A"
For count = 1 to 5
cell = col & count
print cell
Next count
End Sub

 

cheers
andree

 


Hi,
the Excel object let you address any cell by using ActiveWorkbook.Sheets("Sheet1").Cells(row, col)

Sub mytest()
Set cell = ActiveWorkbook.Sheets("Sheet1").Cells(2, 1)     ' writes to cell A2
cell.Value = "RUMBA"
End Sub

In case you want to construct the Range yourself see below sample code:

Sub Main

' cell (row & count)

Dim cell As String
Dim col As String
Dim count As Integer

col = "A"
For count = 1 to 5
cell = col & count
print cell
Next count
End Sub

 

cheers
andree

 

Thank you Andree, but I don't fully understand.

So I  have 50 different groups of the same code, but just changing the column for each group, is there a way to set it so I can just the code once, and loop it, each time moving to the next column or row?

Here is how I currently have it set up:

GoSub PullS1
GoSub PullS2

'*****************************************************************************************************
' Pull
'*****************************************************************************************************
PullS1:
EMReadScreen ScreenText,6,11,95 ' Read the data point
GoodData = Str(ScreenText) ' Convert text to variant
XLSheet.Range("B2") = GoodData ' Write data point from screen to Excel Store 1
EMReadScreen ScreenText,3,11,9 ' Read the data point
GoodData = Str(ScreenText) ' Convert text to variant
XLSheet.Range("A2") = GoodData ' Write data point from screen to Excel Store 1

EMReadScreen ScreenText,8,11,50 ' Read the data point
GoodData = Str(ScreenText) ' Convert text to variant
XLSheet.Range("C2") = GoodData ' Write data point from screen to Excel Store 1

Return

PullS2:
EMReadScreen ScreenText,6,11,95 ' Read the data point
GoodData = Str(ScreenText) ' Convert text to variant
XLSheet.Range("B3") = GoodData
EMReadScreen ScreenText,3,11,9 ' Read the data point
GoodData = Str(ScreenText) ' Convert text to variant
XLSheet.Range("A3") = GoodData ' Write data point from screen to Excel Store 1

EMReadScreen ScreenText,8,11,50 ' Read the data point
GoodData = Str(ScreenText) ' Convert text to variant
XLSheet.Range("C3") = GoodData ' Write data point from screen to Excel Store 1
Return