Saturday, April 2, 2016

Using Arrow keys to move cell to next Column

This post assumes you know about Microsoft Excel and VBA.

I've used the following routine to help separate one list of 100 items into two lists of 50 items each. Each column is for the top 50 and the bottom 50.


Sub OnCtrlShiftRightArrowKeyPress()

s = ActiveCell
addr = ActiveCell.Address

c = ActiveCell.Column + 1
r = FindLastRow((c)) + 1

Cells(r, c) = s
Range(addr).Select

If Not ActiveCell.Font.Strikethrough Then
    DeleteCell
End If

End Sub


In the Worksheet you can add the following

Private Sub Workbook_Activate()
 Application.OnKey "^+{RIGHT}", "ThisWorkbook.OnCtrlShiftRightArrowKeyPress"
 Application.OnKey "^+{LEFT}", "ThisWorkbook.OnCtrlShiftLeftArrowKeyPress"
 '"ThisWorkbook.OnCtrlLeftArrowKeyPress"
End Sub


In a module include the following

Sub DeleteCell()
'
' DeleteCell Macro
'
' Keyboard Shortcut: Ctrl+Shift+M
'
    sCurSheet = ActiveSheet.Name
    sCurCell = ActiveCell.Address
    sCurVal = ActiveCell
    bScreenUpdating = Application.ScreenUpdating
    Application.ScreenUpdating = False
    Logit "@deleted '" & sCurVal & "' from " & sCurCell
    Range("Backup_data") = sCurVal
    
    Selection.Delete Shift:=xlUp '  1004         Cannot use that command on overlapping selections.
    Application.ScreenUpdating = bScreenUpdating

End Sub

No comments:

Post a Comment