VBA - Using table header references

sc247

New Member
Joined
Feb 22, 2018
Messages
6
I am having issue trying to get header references working in a code I'm developing and I'm hoping someone can help!

Instead of using column labels "A" , "B" etc is it possible to use Table header references as I'd like to move / insert columns into the table with more information without having to go through updating the vba code each time?

Simplified version of the current code I'm using;

Sub Calendar ()

Dim Num, Col As Long
Dim myDate

For Num = 2 To 5
myDate = Sheets(List).Cells(Num, "B")
For Col = 2 To 10
If myDate = Sheets(Output).Cells(1, Col) Then
Sheets(Output).Cells(2, Col) = Sheets(List).Cells(Num, "A")
GoTo PASS
End If
Next
PASS:
Next

End Sub

Table;

Worksheet (List)
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Number
[/TD]
[TD]Date
[/TD]
[/TR]
[TR]
[TD]11
[/TD]
[TD]1st April
[/TD]
[/TR]
[TR]
[TD]12
[/TD]
[TD]3rd April
[/TD]
[/TR]
[TR]
[TD]23
[/TD]
[TD]8th April
[/TD]
[/TR]
[TR]
[TD]24
[/TD]
[TD]6th April
[/TD]
[/TR]
</tbody>[/TABLE]

Output;

Worksheet (Output)
[TABLE="width: 500"]
<tbody>[TR]
[TD]Date
[/TD]
[TD]1/4
[/TD]
[TD]2/4
[/TD]
[TD]3/4
[/TD]
[TD]4/4
[/TD]
[TD]5/4
[/TD]
[TD]6/4
[/TD]
[TD]7/4
[/TD]
[TD]8/4
[/TD]
[TD]9/4
[/TD]
[/TR]
[TR]
[TD]Number
[/TD]
[TD]11
[/TD]
[TD][/TD]
[TD]12
[/TD]
[TD][/TD]
[TD][/TD]
[TD]24
[/TD]
[TD][/TD]
[TD]23
[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Forum statistics

Threads
1,223,909
Messages
6,175,314
Members
452,634
Latest member
cpostell

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