ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel

What is Offset in VBA(Visual Basic)?

Updated on February 7, 2012

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.


Fig. 1
Fig. 1

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.



Intelligence Test


view quiz statistics

Comments

    0 of 8192 characters used
    Post Comment

    • profile image

      Lalit Bansal 21 months ago

      Thanks a lot. i understood

    • profile image

      Sania 5 years ago

      good info

    • profile image

      Aiza 5 years ago

      Thanks for this blog..Very detailed in your explanation..

    • profile image

      jasper 5 years ago

      Thanks for this blog..very useful..

    • profile image

      Chris 5 years ago

      Thanks for this post. I have understood it well.

    Click to Rate This Article