finaljustice
Board Regular
- Joined
- Oct 6, 2010
- Messages
- 175
Hey there, I have been writting a code and I decided to use a Do While Loop command to perform what I wished. The problem is, for what I know, the code only follows through if the statement is true. For some reason, the vba code is not understanding or misunderstanding the figures. (Obviouslly this can be a simple mistake, but since I am very tiered I haven't spotted any mistakes)
The problem is that I would expect uprng < maxrng since, the uprng = 2 to start with and maxrng = 1690 ergo, 2<1690 = True.... but it doesn't accept this as true.... if I change the sign around so it becomes uprng > maxrng, aka 2>1690 = TRUE but it's not!!!
If I leave it as last stated, I get in the loop but quickly come out after 3 loops...
I suspect this might be something really simple/ obvious I am missing.
Can anyone shine a light please?
Thanks for your time.
Final
Code:
Sub inputnf()
Dim maxrng, uprng, botrng As Variant
Sheets(1).Select
Range("L2").Select
celladd = ActiveCell.Address
uprng = Replace(celladd, "$", "-", 1, 1)
uprng = Mid(uprng, InStr(1, uprng, "$") + 1, Len(uprng) - InStr(1, uprng, "$"))
maxrng = Range("C1048576").End(xlUp).Address
maxrng = Replace(maxrng, "$", "-", 1, 1)
maxrng = Mid(maxrng, InStr(1, maxrng, "$") + 1, Len(maxrng) - InStr(1, maxrng, "$"))
Do While uprng < maxrng
botrng = Range("L" & uprng).End(xlDown).Offset(-1, 0).Address
botrng = Replace(botrng, "$", "-", 1, 1)
botrng = Mid(botrng, InStr(1, botrng, "$") + 1, Len(botrng) - InStr(1, botrng, "$"))
Range("L" & uprng).Copy
Range("A" & uprng & ":" & "A" & botrng).PasteSpecial (xlPasteValues)
uprng = Range("L" & uprng).End(xlDown).Address
uprng = Replace(uprng, "$", "-", 1, 1)
uprng = Mid(uprng, InStr(1, uprng, "$") + 1, Len(uprng) - InStr(1, uprng, "$"))
Loop
End Sub
The problem is that I would expect uprng < maxrng since, the uprng = 2 to start with and maxrng = 1690 ergo, 2<1690 = True.... but it doesn't accept this as true.... if I change the sign around so it becomes uprng > maxrng, aka 2>1690 = TRUE but it's not!!!
If I leave it as last stated, I get in the loop but quickly come out after 3 loops...
I suspect this might be something really simple/ obvious I am missing.
Can anyone shine a light please?
Thanks for your time.
Final