using a countdown variable in a range

S

Steve

I am trying to duplicate a value from a cell to another cell, and then move
down a cell and copy into that cell aswell, taking into acount that counter1

Heres the code;

counter1 = Range("L6")
contenta1 = Range("m6")
linenumb = 19
If counter1 > 0 Then
linenumb = linenumb + 1
Range("m" & linenumb).Select
ActiveCell.Value = Range("m6")
Range("l" & counter1).Select
ActiveCell.Value = counter1
counter1 = counter1 - 1
Else

End If

It doesnt do what I need it to do, and I think I must be having a blonde
moment because I can't see what;s wrong.
Can anyone help me please

Thanks in advance for all and any help

Steve
 
S

Scott

You should probably be using a while loop, sort of like the following.
(I also modified it so to Range("l" & linenumb).Select instead of using
counter1.

counter1 = Range("L6")
contenta1 = Range("m6")
linenumb = 19
While counter1 > 0
linenumb = linenumb + 1
Range("m" & linenumb).Select
ActiveCell.Value = Range("m6")
Range("l" & linenumb).Select
ActiveCell.Value = counter1
counter1 = counter1 - 1
Wend

You can also do the following:

counter1 = Range("L6")
contenta1 = Range("m6")
linenumb = 19
While counter1 > 0
linenumb = linenumb + 1
Range("m" & linenumb) = contenta1
Range("l" & linenumb) = counter1
counter1 = counter1 - 1
Wend

Scott
 

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

Top