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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,215,095
Messages
6,123,072
Members
449,093
Latest member
ripvw

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