What is Offset in VBA(Visual Basic)?
Offset(0,1)
Offset property in Visual Basic lets you move around the cells in your worksheet in reference to your current position.
The offset code is like this, Range(“Cell Position”).Offset(Row Position, Column Position).
Let's look fig. 1 as an example.
When and how to use offset?
The conversion of this image to VBA code should be "Range(“C2”).Offset(0,-2).Select". This means that the yellow cell is C2 and as well as the integer 0 while -2 is the orange column.
- If you want to move one cell down from the yellow cell, C2, then the code should be Range("C2").Offset(1, 0).Select.
- If you want to move one cell up from the yellow cell, C2, then the code should be Range("C2").Offset(-1, 0).Select.
- If you want to move one cell to the right from the yellow cell, C2, then the code should be Range("C2").Offset(0, 1).Select.
- If you want to move one cell to the left from the yellow cell, C2, then the code should be Range("C2").Offset(0, -1).Select.
Offset could be a great help of you want to take effect something on a particular that depends on the value of other cell. I hope this little explanation could help you understand and use the offset code really well in your Visual Basic Macro programming.
|
|
Microsoft Visual Basic 4.0 Professional Edition (Never Used)
Current Bid: $45.00
|
|
|
Microsoft Visual Basic 6 6.0 Standard & MSDN #3940 Retail Overnight 30day Return
Current Bid: $115.00
|
|
|
MICROSOFT VISUAL BASIC 4.0 4 Professional FULL VERSION PRO CD & Keycode
Current Bid: $69.50
|
Chris 3 months ago
Thanks for this post. I have understood it well.