Macro to move the cursor to a different cell on the same row
I have not written any macro in visual basic at all. I would like to write a
macro with the control key (ctrl r) that allows me to move the cursor to column Y of the same row. For example, if my cursor is on row A12, the activation of this macro should move the cursor to Y12. If my cursor is on row A19, then the cursor should be moved to Y19. Any help is appreciated. |
Macro to move the cursor to a different cell on the same row
This should do the trick
Sub MoveToYColumn() Dim A As Range Set A = ActiveCell ActiveSheet.Cells(A.Row, 25).Select End Sub Assign a keyboard shortcut with Alt-F8 after you have paste the above code into a module. Matt Chen Blue Ridge Telecom "Ann Wong" wrote: I have not written any macro in visual basic at all. I would like to write a macro with the control key (ctrl r) that allows me to move the cursor to column Y of the same row. For example, if my cursor is on row A12, the activation of this macro should move the cursor to Y12. If my cursor is on row A19, then the cursor should be moved to Y19. Any help is appreciated. |
Macro to move the cursor to a different cell on the same row
One way:
First, see David McRitchie's "Getting Started with Macros": http://www.mvps.org/dmcritchie/excel/getstarted.htm Put this in a regular code module: Public Sub MoveToColumnY() Cells(ActiveCell.Row, 25).Activate End Sub In XL, choose Tools/Macros/Macro, select "MoveToColumnY" and click Option. Enter r in the textbox. In article , "Ann Wong" <Ann wrote: I have not written any macro in visual basic at all. I would like to write a macro with the control key (ctrl r) that allows me to move the cursor to column Y of the same row. For example, if my cursor is on row A12, the activation of this macro should move the cursor to Y12. If my cursor is on row A19, then the cursor should be moved to Y19. Any help is appreciated. |
Macro to move the cursor to a different cell on the same row
Hi Ann,
- Open the Visual Basic Editor: ALT+F11 or menu Tools Macros Visual Basic Editor - There, display the Project Explorer window: menu View Project Explorer - Select the book where to store the macro (ibelieve the workbook you are working on): it should be listed in the Project Explorer window. Double-CLick it. - Insert a code module: Insert Module. A blankl module should pop-up. - Add the macro code: copy and paste the code bellow (macro is called MoveCursorToColumnY) in the code module: Sub MoveCursorToColumnY() If Not ActiveCell Is Nothing Then Range("Y" & ActiveCell.Row).Select End If End Sub - Close the Visual Basic Editor and go back to Excel. - Finally, to set up a shortcut key (ctrl+R here), do as if you were running a macro : either click the Run Macro button or menu Tools Macros Macro... The macro dialog pops-up. - In the dialog, select the MoveCursorToColumnY macro and click the Options button. There, you can set the shortcut key as you wish. - Now, just try it. Regards, Sebastien "Ann Wong" wrote: I have not written any macro in visual basic at all. I would like to write a macro with the control key (ctrl r) that allows me to move the cursor to column Y of the same row. For example, if my cursor is on row A12, the activation of this macro should move the cursor to Y12. If my cursor is on row A19, then the cursor should be moved to Y19. Any help is appreciated. |
Macro to move the cursor to a different cell on the same row
You're welcome, Ann.
I am glad i could help. Sébastien "Ann Wong" wrote: Hi Sebastienm, Thank you very much for your help. As a beginner creating Excel Macro, Your detailed instructions certainly make it very easy for me to follow. It worked after my first attempt. Thanks again Best Regards Ann "sebastienm" wrote: Hi Ann, - Open the Visual Basic Editor: ALT+F11 or menu Tools Macros Visual Basic Editor - There, display the Project Explorer window: menu View Project Explorer - Select the book where to store the macro (ibelieve the workbook you are working on): it should be listed in the Project Explorer window. Double-CLick it. - Insert a code module: Insert Module. A blankl module should pop-up. - Add the macro code: copy and paste the code bellow (macro is called MoveCursorToColumnY) in the code module: Sub MoveCursorToColumnY() If Not ActiveCell Is Nothing Then Range("Y" & ActiveCell.Row).Select End If End Sub - Close the Visual Basic Editor and go back to Excel. - Finally, to set up a shortcut key (ctrl+R here), do as if you were running a macro : either click the Run Macro button or menu Tools Macros Macro... The macro dialog pops-up. - In the dialog, select the MoveCursorToColumnY macro and click the Options button. There, you can set the shortcut key as you wish. - Now, just try it. Regards, Sebastien "Ann Wong" wrote: I have not written any macro in visual basic at all. I would like to write a macro with the control key (ctrl r) that allows me to move the cursor to column Y of the same row. For example, if my cursor is on row A12, the activation of this macro should move the cursor to Y12. If my cursor is on row A19, then the cursor should be moved to Y19. Any help is appreciated. |
All times are GMT +1. The time now is 11:41 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com