PC Review


Reply
Thread Tools Rate Thread

Auto-sort data tables after refresh

 
 
PJFry
Guest
Posts: n/a
 
      19th Aug 2009
I have an Excel 2007 workbook that has a number of data tables fed from
Access. The tables contain financial data in a crosstab with the customer
name as the row, the month end date as the column and the sum of the monthly
amounts as the value.

The last column of each table is a sum for YTD 2009. Currently, I go
through each worksheet, update the formula to include the most current month
and sort the total decending. The sort is critical to properly rank the
customers for each worksheet. (I have tried the ranking function, but some
customers will have zero or negative purchases for the year, so I end up with
ties. I have tried many different tie-breaking methods, but all of them have
failed at one point or another).

Here is what I have so far:
Sub SortTables()
Dim ws As Worksheet

Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False

For Each ws In Worksheets

ws.ListObjects("Table_Trinity.accdb6912" _
).Sort.SortFields.Clear
ws.ListObjects("Table_Trinity.accdb6912" _
).Sort.SortFields.Add Key:=Range( _
"Table_Trinity.accdb6912[[#Headers],[SortColumn]]"),
SortOn:=xlSortOnValues, _
Order:=xlDescending, DataOption:=xlSortTextAsNumbers
With ws.ListObjects( _
"Table_Trinity.accdb6912").Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With

Next ws

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub

This works great for the first sheet that has table 6912 on it, but what I
don't know how to do is to replace the "Table_Trinity.accdb6912" with 'the
table on the current worksheet'.

Is there a way to do that?

Thanks!

PJ
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to Refresh inbound data sheets, then Refresh Pivot Tables AFSSkier Microsoft Excel Programming 3 4th Sep 2009 07:59 PM
why sort decending doesn't refresh when data changes? Abdul Microsoft Excel Misc 1 4th Nov 2008 11:37 AM
Auto Refresh of Pivot Tables not working meo Microsoft Excel Worksheet Functions 0 13th Mar 2008 05:31 PM
How can I auto-refresh auto-filters when data changes? =?Utf-8?B?TWlrZUBNUFdjbw==?= Microsoft Excel Worksheet Functions 0 4th Jul 2006 12:50 PM
Pivot Tables -- Auto Refresh Aastha Microsoft Excel Misc 1 30th Mar 2006 08:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:23 PM.