ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Stepping through cells (https://www.excelbanter.com/excel-programming/317968-stepping-through-cells.html)

Kirk[_5_]

Stepping through cells
 
New to the world of Excel VBA programming.

I've used a macro so far to chop a large spreadsheet down to the minimum
info that I need to work with.

It has 13 rows and the number of columns can vary.

Row 1 is a header row (will always have a string value)
Row 2 is a Text ID row (will always have a string value)
Rows 3-13 Text Name row (can have a string value or be empty)

Basically need to parse through the spreadsheet and where the cells in rows
3-13 are not blank do some work. Basically create two lines out to a text
file for each non-emtpy cell.

A B C D etc
1 H1 H2 H3 H4
2 111 222 333 444
3 qrs nji
4 rsd esd
5 fgh asd sew
....
13 ewe erw

For this example set I would get the following to a text file:

TextID1=H1
TextName1=qrs
TextID2=H1
TextName2=fgh
TextID3=H2
TextName3=rsd
TextID4=H2
TextName4=asd
TextID5=H3
TextName5=sew
TextID6=H3
TextName6=ewe
TextID7=H4
TextName7=nji
TextID8=H4
TextName8=esd
TextID9=H4
TextName9=erw

Doing this in C, Pascal or even Fortran would be fairly straight forward but
the Excel VBA cell references and calls is totally unfamiliar. I'm starting
to read up on this to understand how it is handled.

Any help anyone would be willing to give or pointers to some examples that
would lead me in the right direction would be greatly appreciated.

Thanks,
Kirk



Harald Staff

Stepping through cells
 
Hi Kirk

Assuming that you deal with the active sheet, and that the looping is the
problem, not the text generating:

Sub test()
Dim R As Long, C As Long
C = 1
Do
For R = 3 To 13
If Cells(R, C).Value < "" Then
MsgBox "Yo! " & Cells(1, C).Value
MsgBox Cells(R, C).Value
End If
Next
C = C + 1
Loop Until Cells(1, C).Value = ""
End Sub

As you may see, Cells is the magic word, addressed like
Cells(Rownumber, Columnnumber)

HTH. Best wishes Harald

"Kirk" skrev i melding
...
New to the world of Excel VBA programming.

I've used a macro so far to chop a large spreadsheet down to the minimum
info that I need to work with.

It has 13 rows and the number of columns can vary.

Row 1 is a header row (will always have a string value)
Row 2 is a Text ID row (will always have a string value)
Rows 3-13 Text Name row (can have a string value or be empty)

Basically need to parse through the spreadsheet and where the cells in

rows
3-13 are not blank do some work. Basically create two lines out to a text
file for each non-emtpy cell.

A B C D etc
1 H1 H2 H3 H4
2 111 222 333 444
3 qrs nji
4 rsd esd
5 fgh asd sew
...
13 ewe erw

For this example set I would get the following to a text file:

TextID1=H1
TextName1=qrs
TextID2=H1
TextName2=fgh
TextID3=H2
TextName3=rsd
TextID4=H2
TextName4=asd
TextID5=H3
TextName5=sew
TextID6=H3
TextName6=ewe
TextID7=H4
TextName7=nji
TextID8=H4
TextName8=esd
TextID9=H4
TextName9=erw

Doing this in C, Pascal or even Fortran would be fairly straight forward

but
the Excel VBA cell references and calls is totally unfamiliar. I'm

starting
to read up on this to understand how it is handled.

Any help anyone would be willing to give or pointers to some examples that
would lead me in the right direction would be greatly appreciated.

Thanks,
Kirk






All times are GMT +1. The time now is 08:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com