Stepping through cells

K

Kirk

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
 
H

Harald Staff

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
 

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