Using a range of column names

AlexanderBB

Well-known Member
Joined
Jul 1, 2009
Messages
2,097
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
If I set a range to a row in my Worksheet I can refer to each column by it's index number.
But what If I'd like to use column names instead?
My thinking is too add a class module but then I'd have to populate it by the range and there'd be no advantage. Is there a better way ?
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
The question is not totally clear, but could you use something like:

VBA Code:
Set r = Rows(5)
MsgBox r.Cells(1, "AA").Address
 
Upvote 0
I'll give an example
Row 1 Col "I" is "Artist"
Private Sub Worksheet_SelectionChange(ByVal Target As Range
Set iRange = Range("A" & Target.Row & ":Z" & Target.Row)
end Sub
? Range(5) ... will show the current row, column "I".
But instead of range(5) I want to be able to use myRange,Artist.
 
Upvote 0
iRange(5) will show current row, column E.

VBA Code:
Artist = "I"
x = iRange.Cells(1, Artist)

will populate x with the value of current row, column I.

(But note that the "I" reference here is relative. It will get the 9th column in iRange, which is I only if iRange starts in column A)
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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