Jump to content
Macro Express Forums

Challenge: hotkeys to move text without selecting


Recommended Posts

Here are my scripts for moving an entire Excel row down and up, without the need to select the row. The row that is moved is always the one that has keyboard focus.

 

Each script is only five lines long. I tested a version that combined all five lines into a single "Text Type" instruction. It worked. But the challenge wasn’t to create a solution with the fewest lines of code. It’s much clearer when broken up this way:

 

Move row down:

 

Text Type (Simulate Keystrokes): <HOME> // Must start selection from Column A
Text Type (Simulate Keystrokes): <SHIFT><SPACE> // Select the row
Text Type (Simulate Keystrokes): <CONTROL>x
Text Type (Simulate Keystrokes): <ARROW DOWN><ARROW DOWN>
Text Type (Simulate Keystrokes): <SHIFT><CONTROL>= // Insert a row

 

<TEXT TYPE Action="0" Text="<HOME>" _COMMENT="Must start selection from Column A "/>
<TEXT TYPE Action="0" Text="<SHIFT><SPACE>" _COMMENT="Select the row"/>
<TEXT TYPE Action="0" Text="<CONTROL>x"/>
<TEXT TYPE Action="0" Text="<ARROW DOWN><ARROW DOWN>"/>
<TEXT TYPE Action="0" Text="<SHIFT><CONTROL>=" _COMMENT="Insert a row"/>

 

Move row up:

 

Text Type (Simulate Keystrokes): <HOME> // Must start selection from Column A
Text Type (Simulate Keystrokes): <SHIFT><SPACE> // Select the row
Text Type (Simulate Keystrokes): <CONTROL>x
Text Type (Simulate Keystrokes): <ARROW UP>
Text Type (Simulate Keystrokes): <SHIFT><CONTROL>= // Insert a row

 

<TEXT TYPE Action="0" Text="<HOME>" _COMMENT="Must start selection from Column A "/>
<TEXT TYPE Action="0" Text="<SHIFT><SPACE>" _COMMENT="Select the row"/>
<TEXT TYPE Action="0" Text="<CONTROL>x"/>
<TEXT TYPE Action="0" Text="<ARROW UP>"/>
<TEXT TYPE Action="0" Text="<SHIFT><CONTROL>=" _COMMENT="Insert a row"/>

 

If you want to try these scripts, set scope to window-specific. Depending on the version of Excel you are using, you will either need to specify a partial match to:

 

"Excel -"

     or

"- Excel"

 

Check the title bar in Excel to discover whether the hyphen goes before or after the word "Excel."

 

The hotkeys I chose for these scripts are Alt + Shift + down arrow (to move the row down), and Alt + Shift + up arrow (to move the row up). I opted for these hotkeys because they parallel the hotkeys available by default in Word, Outlook, and PowerPoint. But of course you can choose any activation you like.

 

Link to comment
Share on other sites

You're right, rberq, it took digging before I stumbled upon Shift + Ctrl + equal sign. As a (mostly) non-mouse user, I already knew Home (go to start of row) and Shift + spacebar (select row).

 

Edited:

 

Only today did I abandon the quest to come up with a satisfactory solution for moving columns. The task requires the insertion point to jump to the topmost cell in a column. I have not yet discovered a way to do this via keyboard that works in every Excel worksheet. My solution sometimes fails.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...