Gallaxhar
Gallaxhar

Reputation: 1036

How to select data from a column while in a For Each range loop?

I have a For Each loop reading the values of K2 through K7.

It looks like this (this is not my full code):

For Each cell In Range("K2:K7")
'do stuff
Next cell

How can I get data from another column (such as A, B, C, D, E, F, G, H, I, or J) on the CURRENT row of the "For Each" loop.

For example, first the For Each loop will grab K2, then K3, then K4, then K5, then K6, then K7. How to make it grab K2 and A2, K3 and A3, K4 and A4, etc. in the same For Each loop?

For example:

For Each cell In Range("K2:K7")
A.CurrentRow.Value = acolumndata
B.CurrentRow.Value = bcolumndata
C.CurrentRow.Value = ccolumndata
'do more stuff
Next cell

Upvotes: 1

Views: 52

Answers (1)

Isaac Moses
Isaac Moses

Reputation: 1609

One way to do this would be to use the Offset property.

For example, to refer to the cell in Column A that's on the same row as the current cell in Column K, you would use cell.Offset(0, -10), since Column A is 10 columns to the left of Column K.

Upvotes: 1

Related Questions