bearcub
Well-known Member
- Joined
- May 18, 2005
- Messages
- 711
- Office Version
- 365
- 2013
- 2010
- 2007
- Platform
- Windows
I'm trying to get comfortable again using VBA so I'm trying to force myself to understand loops. I'm getting to point where i understand them better and I actually feel comfortable using them slightly but I've always been confused by nested For or Do loops. I remember 12-13 years ago when I was learning JAVA I spent hours tinkering with the loops to understand what would happen if I did this or I did that.
I had posted an earlier post this morning with 2 questions and the first question was answered - thank you for that. The answers were marvelous! Can't wait to get home to tinker with them to get a better understanding how they work.
But I guess I'm only allowed only 1 question per thread because the second one was never answered.
I would try to google to find the answer myself but I don't know what to call this kind of loop - could it be called a "snake loop"?
I would like to create the following output:
1 6 7 12 13
2 5 8 11 14
3 4 9 10 15
I have a basic piece of code that I picked up and understand pretty well but how could the following loop be tweaked to create the previous output:
Sub ListofNumbers()
Dim ManyCells As Range
Dim c As Range
Dim J As Integer
Set ManyCells = Range("C4:J27")
J = 1
For Each c In ManyCells
c.Value = J
J = J + 1
Next c
End Sub
Thank you for your help.
Michael
I had posted an earlier post this morning with 2 questions and the first question was answered - thank you for that. The answers were marvelous! Can't wait to get home to tinker with them to get a better understanding how they work.
But I guess I'm only allowed only 1 question per thread because the second one was never answered.
I would try to google to find the answer myself but I don't know what to call this kind of loop - could it be called a "snake loop"?
I would like to create the following output:
1 6 7 12 13
2 5 8 11 14
3 4 9 10 15
I have a basic piece of code that I picked up and understand pretty well but how could the following loop be tweaked to create the previous output:
Sub ListofNumbers()
Dim ManyCells As Range
Dim c As Range
Dim J As Integer
Set ManyCells = Range("C4:J27")
J = 1
For Each c In ManyCells
c.Value = J
J = J + 1
Next c
End Sub
Thank you for your help.
Michael