I utilise Excel a heap as digital graph paper by reducing column widths to make squares. I then use the border tools to draw, which involves selecting cells. To make this easier I'm working on a shortcut macro to select the required cells with respect to the currently selected cell as the start point. If both X and Y axis values are positive, I have no problem, but I can't work out how to use negative references to go left and/or up from my starting point. My macro as it is currently is:
I presume my problem is that I can't do a maths operation within the Offset function. Is that correct?
VBA Code:
Sub SelectCells()
Dim SelCols As Single, SelRows As Single
SelCols = Application.InputBox("Enter X axis cells to select")
If SelCols = False Then
Exit Sub
End If
SelRows = Application.InputBox("Enter Y axis cells to select")
If SelRows = False Then
Exit Sub
End If
If SelCols < 0 And SelRows > 0 Then 'if start point cell is TOP RIGHT
ActiveCell.Offset(0, SelCols + 1).Resize(SelRows, SelCols).Select
ElseIf SelCols > 0 And SelRows < 0 Then ' if start point cell is BOTTOM LEFT
ActiveCell.Offset(SelRows + 1, 0).Resize(SelRows, SelCols).Select
ElseIf SelCols < 0 And SelRows < 0 Then ' if start point cell is BOTTOM RIGHT
ActiveCell.Offset(SelRows + 1, SelCols + 1).Resize(SelRows, SelCols).Select
Else: ActiveCell.Resize(SelRows, SelCols).Select 'if start point cell is TOP LEFT
End If
End Sub
I presume my problem is that I can't do a maths operation within the Offset function. Is that correct?