Using Named Ranges as column references?

jmpatrick

Active Member
Joined
Aug 17, 2016
Messages
477
Office Version
  1. 365
Platform
  1. Windows
Good morning.

I have a general design question that has plagued me for years. Here's some example code:

VBA Code:
    Range(Cells(Selection.Row, 15).Address).Select
    Range(ActiveCell.Address).Name = "StartCell"
    Sheets("Hyperlinks").Range("F1") = Sheets("Calendar").Range("StartCell")
    Sheets("Hyperlinks").Range("A1") = Sheets("Calendar").Range("C" & ActiveCell.Row).Value

The code above works fine as long as columns are not added or deleted. Once you do, all references are broken. Is it possible to use a named range instead of specifying a column? That way, when columns are added or deleted everything still works.

These are the things that tend to break:

VBA Code:
Range(Cells(Selection.Row, 15).Address).Select
VBA Code:
Sheets("Hyperlinks").Range("A1") = Sheets("Calendar").Range("C" & ActiveCell.Row).Value

As it is now, adding or deleting rows is an ordeal that requires changing dozens of macros.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,214,918
Messages
6,122,243
Members
449,075
Latest member
staticfluids

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