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]
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]