Why doesn't this simple macro work

  • Thread starter Thread starter donbowyer
  • Start date Start date
D

donbowyer

Sub MyNext()
For X = 1 To 10 Step 1
For Y = 1 To 40 Step 4
Range("A" & Y) = X & "Words"
Next Y
Next X
End Sub
Y iterates OK but X never gets a look in??
 
What are you expecting it to do because (probably infuriatingly for you)it
is doing ecactly what you are telling it to do which is

Write "1WORDS" to a1, A5 down to A37
The 1 comes from the X loop and words from the Y loop
The macrow then overwrites each of these cells with 2Words, 3words etc up to
10Words.

Mike
 
Hi Mike
Yes I agree.
What I would like it to do is put "1Word" in Cell A1, then
"2Word" in cell A5, then "3Word" in A9 etc
Don
 
Try this

Sub MyNext()
x = 1
For Y = 1 To 40 Step 4
Range("A" & Y) = x & "Words"
x = x + 1
Next
End Sub

Mike
 
Which of course works.
Many thanks - the simple answer was elududing me
Don
 
Surely this line: Range("A" & Y) = x & "Words"
should read: Range("A" & Y) = str(x,0) & "Words"
scooper
 

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

Back
Top