Get column number by header name

ArrayON_56

New Member
Joined
Jul 9, 2021
Messages
9
Office Version
  1. 2019
Platform
  1. Windows
I'm new to VBA Excel programming.
I have a table with several headers and I would want to get absolute column number of some header.
To be more clear. There is a form to which user should enter header name (practically header cell content) and the program should get absolute column number where the header is placed in sheet. The column number will be parsed to next code which already exists.
Is there some simple way how to do it, or I have to cycle through each and check if cell(header) content equals to phrase I'm searching for?
Thanks.

PS: I was able to get only here: ActiveSheet.ListObjects("TranslationDataTable").ListColumns("<Some-Header-Name-Here>"), but it only returns content of the cell, and that is practically header name. TranslationDataTable is name of the table I'm searching in.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I don’t have my computer in front of me but try adding “.Index” without quotes to the end of your ListColumns statement.
ActiveSheet.ListObjects("TranslationDataTable").ListColumns(“Some-Header-Name-Here").Index
Assuming you mean position in the table not the column number in the sheet
 
Upvote 0
Solution
Thanks for answers.
Yes, I mean column number in sheet, but since the table will always start at 1;1, adding .index will work for me.
 
Upvote 0
Thanks for answers.
Yes, I mean column number in sheet, but since the table will always start at 1;1, adding .index will work for me.

If you are wanting to return the column number in the sheet you are better off using ".Range.Column" instead of ".Index"
eg
ActiveSheet.ListObjects("TranslationDataTable").ListColumns(“Some-Header-Name-Here").Range.Column
 
Upvote 0

Forum statistics

Threads
1,224,918
Messages
6,181,742
Members
453,064
Latest member
robatthe2A

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