Table Look Up Help in VBA

frabulator

Active Member
Joined
Jun 27, 2014
Messages
250
Office Version
  1. 2019
Platform
  1. Windows
I have been tasked with managing a very large vlookup spreadsheet that spans several disorganized books, which I promptly said, 'screw that' after I saw the mess of and organization nightmare I was getting into. So I came up with a userform that breaks down the vlookup into workbooks, sheets, tables and headers. Works beautiful, except I hit a road block.

My question is, what is the syntax to call the individual values for the HeaderRowRange of a table? IE, how can I list/loop each cell value in that headerrowrange? I am sure it is something simple that I am overlooking, but I cant seem to get it to work.

Thanks in advance
~Frab
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try:
VBA Code:
Sub ActivateHeaderRow()
 Dim wrksht As Worksheet
 Dim objList As ListObject
 Dim objListRng As Range
 
 Set wrksht = ThisWorkbook.Worksheets("Sheet1")
 Set objList = wrksht.ListObjects(1)
 Set objListRng = objList.HeaderRowRange
 

Dim c As Range

'loop each header
For Each c In objListRng
    Debug.Print c.Value
Next

Debug.Print objListRng.Cells(2).Value  'return the second header

End Sub
 
Upvote 0
Try:
VBA Code:
Sub ActivateHeaderRow()
 Dim wrksht As Worksheet
 Dim objList As ListObject
 Dim objListRng As Range
 
 Set wrksht = ThisWorkbook.Worksheets("Sheet1")
 Set objList = wrksht.ListObjects(1)
 Set objListRng = objList.HeaderRowRange
 

Dim c As Range

'loop each header
For Each c In objListRng
    Debug.Print c.Value
Next

Debug.Print objListRng.Cells(2).Value  'return the second header

End Sub
Wow! Quick reply :) Thank you!
I will give this a shot when I get back to my work computer.
 
Upvote 0
Try:
VBA Code:
Sub ActivateHeaderRow()
 Dim wrksht As Worksheet
 Dim objList As ListObject
 Dim objListRng As Range
 
 Set wrksht = ThisWorkbook.Worksheets("Sheet1")
 Set objList = wrksht.ListObjects(1)
 Set objListRng = objList.HeaderRowRange
 

Dim c As Range

'loop each header
For Each c In objListRng
    Debug.Print c.Value
Next

Debug.Print objListRng.Cells(2).Value  'return the second header

End Sub

The code provided returns the headers. I need to individual values from those headers.

For instance, the header might be "Name". I would like to return "Sam", "Jim", "Pete" etc.

Any idea how to do that?
 
Last edited:
Upvote 0
The code provided returns the headers. I need to individual values from those headers.

For instance, the header might be "Name". I would like to return "Sam", "Jim", "Pete" etc.

Any idea how to do that?


For anyone wondering, I was able to figure this out by looping the header and calling cell values from each one.

If there is a better way please let me know.
 
Upvote 0

Forum statistics

Threads
1,215,110
Messages
6,123,138
Members
449,098
Latest member
Doanvanhieu

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