ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I refer (in VBA Code) to a column by caption instead of index ? (https://www.excelbanter.com/excel-programming/347749-how-do-i-refer-vba-code-column-caption-instead-index.html)

Radu

How do I refer (in VBA Code) to a column by caption instead of index ?
 
Thanks a lot...

Alex. Nitulescu


Lonnie M.

How do I refer (in VBA Code) to a column by caption instead of index ?
 
Do you mean:
Columns("G").Select
OR:
Columns("G:G").Select

Instead of:
Columns(7).Select

Or something else?


Radu

How do I refer (in VBA Code) to a column by caption instead of index ?
 
No, I was referring to something like

Columns("My wonderful new caption") instead of Columns(4), or
Columns("G")...


Leith Ross[_358_]

How do I refer (in VBA Code) to a column by caption instead of index ?
 

Hello Radu,

Put your caption in Row 1. Select the Column by clicking the column
letter. Click *Insert* on the menu bar and select *Name*. Check that
the entire column is selected. Look at the *Refers to:* box. If you
selected column "G" on sheet 1 you will see "=Sheet1!$G:$G". The double
column letter indicates the entire column is selected.

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=492248


Radu

How do I refer (in VBA Code) to a column by caption instead of index ?
 
Thank you, Ross.... What I need is this:

In a module (VBA code) I need to be able to refer to columns in my
spreadsheet not by position, since the user might change the columns'
order, but by Caption (the caption is NOT negociable).

So in the first row I have the captions, like
Caption 1 Caption 2 Caption 3
and in the subsequent rows I have the data:
a b c
d e f

I need to be able to write in code NOT .Columns(2), NOT columns ("B"),
since the columns might move, but .Columns("Caption 2")...

Radu


Niek Otten

How do I refer (in VBA Code) to a column by caption instead of index ?
 
Record a macro while doing this:
Select your columns
InsertNameCreate
check Top row

Include this in your code

Now you can refer to the columns:

..Range("Caption2")


--
Kind regards,

Niek Otten



"Radu" wrote in message
oups.com...
Thank you, Ross.... What I need is this:

In a module (VBA code) I need to be able to refer to columns in my
spreadsheet not by position, since the user might change the columns'
order, but by Caption (the caption is NOT negociable).

So in the first row I have the captions, like
Caption 1 Caption 2 Caption 3
and in the subsequent rows I have the data:
a b c
d e f

I need to be able to write in code NOT .Columns(2), NOT columns ("B"),
since the columns might move, but .Columns("Caption 2")...

Radu





All times are GMT +1. The time now is 07:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com