ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   How to write macro that selects relative locations (https://www.excelbanter.com/excel-worksheet-functions/109574-how-write-macro-selects-relative-locations.html)

NewKid

How to write macro that selects relative locations
 
I am using the macro recorder and have it turns to RELATIVE recording rather
than ABSOLUTE recording, but... I cannot figure out how to record navigation
keys relative to my current location. For example, when I press the HOME
key, I want the macro to just go to the far left column for the current row.
When I press the UP ARROW, I want the macro to move up one cell from the
current location. Even with the RELATIVE recording on, it still puts
absolute references in the macro.

How can I get around this? THANKS IN ADVANCE FOR ANY HELP YOU CAN OFFER!



Bernie Deitrick

How to write macro that selects relative locations
 
To select the first column of the activecell's row (similar to Home)

Cells(Activecell.Row,1).Select

To move up one cell: ActiveCell.Offset(-1,0).Select
To move down one cell: ActiveCell.Offset(1,0).Select
To move right one cell: ActiveCell.Offset(0,1).Select
To move left one cell: ActiveCell.Offset(0, -1).Select

But you rarely need to select anything....

HTH,
Bernie
MS Excel MVP


"NewKid" wrote in message
...
I am using the macro recorder and have it turns to RELATIVE recording rather
than ABSOLUTE recording, but... I cannot figure out how to record navigation
keys relative to my current location. For example, when I press the HOME
key, I want the macro to just go to the far left column for the current row.
When I press the UP ARROW, I want the macro to move up one cell from the
current location. Even with the RELATIVE recording on, it still puts
absolute references in the macro.

How can I get around this? THANKS IN ADVANCE FOR ANY HELP YOU CAN OFFER!





NewKid

How to write macro that selects relative locations
 
Thank you! Worked perfectly!

"Bernie Deitrick" wrote:

To select the first column of the activecell's row (similar to Home)

Cells(Activecell.Row,1).Select

To move up one cell: ActiveCell.Offset(-1,0).Select
To move down one cell: ActiveCell.Offset(1,0).Select
To move right one cell: ActiveCell.Offset(0,1).Select
To move left one cell: ActiveCell.Offset(0, -1).Select

But you rarely need to select anything....

HTH,
Bernie
MS Excel MVP


"NewKid" wrote in message
...
I am using the macro recorder and have it turns to RELATIVE recording rather
than ABSOLUTE recording, but... I cannot figure out how to record navigation
keys relative to my current location. For example, when I press the HOME
key, I want the macro to just go to the far left column for the current row.
When I press the UP ARROW, I want the macro to move up one cell from the
current location. Even with the RELATIVE recording on, it still puts
absolute references in the macro.

How can I get around this? THANKS IN ADVANCE FOR ANY HELP YOU CAN OFFER!







All times are GMT +1. The time now is 05:41 AM.

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