ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   loop through columns (using for-loop) (https://www.excelbanter.com/excel-programming/401599-loop-through-columns-using-loop.html)

Kurt[_3_]

loop through columns (using for-loop)
 
Hello,

I now discovered the syntax to loop through rows:
example:

For i = 3 To 20
If Range("A" & i).Value = "" Then
Range("A" & 1).Copy Destination:=Range("A" & i)
End If
Next i

How can I use the same method for scrolling trough columns?
How can I get to column B using something like "A+1"

extra question: why is the "Next i" placed behind the for-loop? Isn't
it placed in the for-loop with other languages?

Thanks in advance!

Per Jessen[_2_]

loop through columns (using for-loop)
 
On 23 Nov., 20:08, Kurt wrote:
Hello,

I now discovered the syntax to loop through rows:
example:

For i = 3 To 20
If Range("A" & i).Value = "" Then
Range("A" & 1).Copy Destination:=Range("A" & i)
End If
Next i

How can I use the same method for scrolling trough columns?
How can I get to column B using something like "A+1"

extra question: why is the "Next i" placed behind the for-loop? Isn't
it placed in the for-loop with other languages?

Thanks in advance!


Hi Kurt

MyRow = 1
For i = 3 To 20
If Cells(MyRow, i).Value = "" Then Cells(MyRow, i) = Cells(MyRow,
1).Value
Next

Regards,

Per

JLGWhiz

loop through columns (using for-loop)
 
Here is a place to answer some questions:

http://www.excel-vba.com/excel-vba-contents.htm

Just start at the beginning and work your way through. It explains a lot of
the basics and gives examples..


"Kurt" wrote:

Hello,

I now discovered the syntax to loop through rows:
example:

For i = 3 To 20
If Range("A" & i).Value = "" Then
Range("A" & 1).Copy Destination:=Range("A" & i)
End If
Next i

How can I use the same method for scrolling trough columns?
How can I get to column B using something like "A+1"

extra question: why is the "Next i" placed behind the for-loop? Isn't
it placed in the for-loop with other languages?

Thanks in advance!



All times are GMT +1. The time now is 09:42 AM.

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