ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   using a countdown variable in a range (https://www.excelbanter.com/excel-programming/378381-using-countdown-variable-range.html)

Steve

using a countdown variable in a range
 
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
0;


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



ALATL

using a countdown variable in a range
 
Have you tried using the debugger and tracing through your code?

"Steve" wrote:

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
0;


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



Scott

using a countdown variable in a range
 
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

Steve wrote:
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
0;


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



Steve

using a countdown variable in a range
 
Thank you very much


All times are GMT +1. The time now is 01:38 PM.

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