Using Offset to select negative cell range using variables

Yamezz

Active Member
Joined
Nov 22, 2006
Messages
364
Office Version
  1. 2019
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:
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?
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Never mind... I finally realised I was still trying to feed Resize with negative numbers!
 
Upvote 0

Forum statistics

Threads
1,223,954
Messages
6,175,601
Members
452,658
Latest member
GStorm

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