macro to move cursor to specific userform textbox

richardcarter

Board Regular
Joined
Dec 10, 2003
Messages
77
I'm trying to create a keyboard shortcut which will run a macro which will move the cursor to a specific textbox in a userform.

This is the macro I have to move the cursor:

Private Sub Cursor_to_textbox1()
textbox1.SetFocus
End Sub

Because the above macro is a 'Private Sub' macro, I cannot create a normal keyboard shortcut, so I understand from other posts that I need to use the following to create the shortcut (which is placed in the 'This Workbook' module):

Private Sub Workbook_Test()
Application.OnKey "+Q", "textbox1"
End Sub

However, the above code doesn't seem to work correctly because when I press SHIFT+Q when the userform is open, all it does is place the letter 'Q' in the textbox which the cursor is currently in.

Any ideas?
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top