I am having trouble accessing the Excel ListObject object using VBA code where I keep getting Subscript out of range errors as if there are no recognised lists on the spreadsheet where I try to run the code. I can see the list and I know the sheet is active when I run the test below. I was of the expectation that once there was a header row and record rows underneath Excel automatically recognises it as a list or at least that is how it works when using the manual interface Data Sort and Filter functionality through the Excel UI. Do I need to do something different in VBA to define a list? When I click a cell inside the list the list Tab is NOT activiates so what turned this on?</SPAN>
To bring things back to basics I have tested with this code running on a new workbook which has a basic list of 3 rows and 3 columns.</SPAN>
Sub ActivateHeaderRow1()</SPAN>
Dim wrksht As Worksheet</SPAN>
Dim objList As ListObject</SPAN>
Dim objListRng As Range</SPAN>
Set wrksht = ActiveWorkbook.ActiveSheet</SPAN>
Set objList = wrksht.ListObjects(1)</SPAN>
Set objListRng = objList.HeaderRowRange</SPAN>
objListRng.Activate</SPAN>
End Sub</SPAN>
This is my basic list.</SPAN>
date time hours</SPAN>
1/05/2014 2:15 5</SPAN>
2/05/2014 3:15 4</SPAN>
3/05/2014 4:15 6</SPAN>
It fails on this line:</SPAN>
Set objListRng = objList.HeaderRowRange
What is the VBA code to make a list act like a list?
Any suggestions appreciated.
</SPAN>
To bring things back to basics I have tested with this code running on a new workbook which has a basic list of 3 rows and 3 columns.</SPAN>
Sub ActivateHeaderRow1()</SPAN>
Dim wrksht As Worksheet</SPAN>
Dim objList As ListObject</SPAN>
Dim objListRng As Range</SPAN>
Set wrksht = ActiveWorkbook.ActiveSheet</SPAN>
Set objList = wrksht.ListObjects(1)</SPAN>
Set objListRng = objList.HeaderRowRange</SPAN>
objListRng.Activate</SPAN>
End Sub</SPAN>
This is my basic list.</SPAN>
date time hours</SPAN>
1/05/2014 2:15 5</SPAN>
2/05/2014 3:15 4</SPAN>
3/05/2014 4:15 6</SPAN>
It fails on this line:</SPAN>
Set objListRng = objList.HeaderRowRange
What is the VBA code to make a list act like a list?
Any suggestions appreciated.
</SPAN>