Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #5  
Old 09-19-2013, 07:25 AM
BobBridges's Avatar
BobBridges BobBridges is offline VBA sort table code Windows 7 64bit VBA sort table code 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
 

Tags
range, sort, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook Combobox Sort Code lms Outlook 1 09-18-2013 09:56 AM
VBA sort table code How to Sort Table Cells from Left to Right tamaracklodge Word Tables 4 03-04-2013 04:00 AM
Sort table using macro saslotteroy Word VBA 2 09-15-2011 02:41 PM
VBA sort table code How to sort table having three columns? Bahir Barak Word 2 01-20-2011 01:52 PM
Can I sort a Pivot table by subtotals? oshkosh Excel 1 12-07-2010 06:20 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:57 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft