![]() |
Why doesn't this simple macro work
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?? -- donwb |
Why doesn't this simple macro work
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 "donbowyer" wrote: 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?? -- donwb |
Why doesn't this simple macro work
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 -- donwb "Mike H" wrote: 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 "donbowyer" wrote: 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?? -- donwb |
Why doesn't this simple macro work
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 "donbowyer" wrote: 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 -- donwb "Mike H" wrote: 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 "donbowyer" wrote: 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?? -- donwb |
Why doesn't this simple macro work
Which of course works.
Many thanks - the simple answer was elududing me Don -- donwb "Mike H" wrote: 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 "donbowyer" wrote: 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 -- donwb "Mike H" wrote: 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 "donbowyer" wrote: 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?? -- donwb |
Why doesn't this simple macro work
Your welcome
"donbowyer" wrote: Which of course works. Many thanks - the simple answer was elududing me Don -- donwb "Mike H" wrote: 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 "donbowyer" wrote: 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 -- donwb "Mike H" wrote: 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 "donbowyer" wrote: 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?? -- donwb |
Why doesn't this simple macro work
Surely this line: Range("A" & Y) = x & "Words" should read: Range("A" & Y) = str(x,0) & "Words" scooper "Mike H" wrote in message ... Your welcome "donbowyer" wrote: Which of course works. Many thanks - the simple answer was elududing me Don -- donwb "Mike H" wrote: 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 "donbowyer" wrote: 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 -- donwb "Mike H" wrote: 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 "donbowyer" wrote: 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?? -- donwb |
All times are GMT +1. The time now is 02:46 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com