VBA Reference to Relative Cells

AcornNut

Board Regular
Joined
Aug 19, 2014
Messages
51
I have a code that, when a cell is selected it calls a module to run that code. I'm using the Select Case code to accomplish this. It's working great, but the problem is, sometimes I have to insert or delete rows on the page, which changes the cell reference of the cell I want to select. Is there a code that will keep the cell reference regardless of where the cell moves to (ie. relative reference)? In the example below, if I click B198, it runs the module for "FillOrder" just fine. But if I have to delete a row before it, then that cell moves to B197. How can I get this code to continue to reference that new location? Or is there another way to do this?

Example
VBA Code:
'Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim Resp As Long
Dim g As String

 If Not Intersect(ActiveCell, Range("B9", "B459")) Is Nothing Then
    Select Case ActiveCell.Address(0, 0)
           Case "B198"
             FillOrder
    End Select
 End If
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,223,909
Messages
6,175,313
Members
452,634
Latest member
cpostell

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