I have some VBA that will attempt to select cells in a direction with a button press. I would like the left and right buttons to extend the selection. In the code I have left arrow only selecting current - 1 column, but ideally, it would go -1 column until a single column is selected, and then go left). The up and down buttons should go up or down an entire block of cells (separated by an entirely blank row of a table). I need some help with the up arrow or if anyone has done this before, a solution using ActiveCell. Because if a user selects a cell the down array should select the whole current block of cells down to the blank, and proceed to the next block if clicked again. So, in other words, move up or down should be dynamic with cell or range selection. However, that seems difficult to make exceptions for in the current code.
VBA Code:
Sub Extend_Selection_Right_Column()
'Extend selection one column to the right
On Error Resume Next
Range(Selection, Selection.End(xlDown)).Select
Selection.Resize(Selection.Rows.Count, Selection.Columns.Count + 1).Select
On Error GoTo 0
End Sub
Sub Move_Selection_Left_Column()
'Moves selection one column to the left
On Error Resume Next
Range(Selection, Selection.End(xlDown)).Select
Selection.Resize(Selection.Rows.Count, Selection.Columns.Count - 1).Select
On Error GoTo 0
End Sub
Sub Move_Selection_Down_Block()
'Moves selection down one block
On Error Resume Next
Dim rng As Range
Set rng = Selection
rng(rng.Count).Offset(2, 0).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Resize(Selection.Rows.Count, Selection.Columns.Count).Select
On Error GoTo 0
End Sub
Sub Move_Selection_Up_Block()
'Moves selection up one row block
On Error Resume Next
Dim rng As Range
Set rng = Selection
rng(rng.Count).Offset(-rng.Count - 1, 0).Select
Range(Selection, Selection.End(xlUp)).Select
Selection.Resize(Selection.Rows.Count, Selection.Columns.Count).Select
On Error GoTo 0
End Sub