Macro to move the cursor to a different cell on the same row

G

Guest

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.
 
G

Guest

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top