illusionek
Board Regular
- Joined
- Jun 21, 2014
- Messages
- 102
Hi
Can anyone please explain why below code works?
If I do debug.print x I can see that x got value of the last cell rather than the address of last cell. So it is not clear to me how below loop works if as a second argument of Range I entered is x, which should not provide correct value (according to debug.print) but code is working well. So I am not sure what’s going on here. When I tried to assing ActiveCell.SpecialCells(xlCellTypeLastCell).Address to x I got mismatch error.
Can anyone please explain why below code works?
If I do debug.print x I can see that x got value of the last cell rather than the address of last cell. So it is not clear to me how below loop works if as a second argument of Range I entered is x, which should not provide correct value (according to debug.print) but code is working well. So I am not sure what’s going on here. When I tried to assing ActiveCell.SpecialCells(xlCellTypeLastCell).Address to x I got mismatch error.
Code:
Sub test()
Dim x As Range
Set x = ActiveCell.SpecialCells(xlCellTypeLastCell)
For Each x In Range("d4", x)
x.Offset(0, 1) = x * 1.5
Next x
End Sub