View Single Post
 
Old 09-19-2013, 07:25 AM
BobBridges's Avatar
BobBridges BobBridges is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default

This is 'way more sophisticated than anything I've tried to do in Excel before. In Access, sure, but I've never used real forms in Excel, never more than the occasional button. I had to do some exploring to see how this thing hangs together. I'm impressed.

But I think I see what the problem is. You can, too: Put a break on the statement that's hanging up:
Code:
.Sort.SortFields.Add Key:=.ListColumns(1), _
         SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortTextAsNumbers
...and then run the program. When it pauses, Add Watch for the parent object, Range(pcEditTable); drill down through .ListObject to .ListColumns, and you'll see that each item in the collection is of type ListColumn.

But Sortfields.Add Key:= wants not a ListColumn object but a Range; that's why the other form of the command works. I don't know anything about ListObjects, but I opened up one of the ListColumn objects and I see that Range is one of its properties. I infer that ListColumn is has many non-range properties so it can't be a range itself, but offers you the range as one of the properties.

I changed your statement, therefore, to
Code:
.Sort.SortFields.Add Key:=.ListColumns(1).Range, _
         SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortTextAsNumbers
...and VBA accepted it. What I mean is that it executed the statement without complaining about an error. You will know better than I whether that actually fixes the problem.
Reply With Quote