VBA Sorting excel table linked to other tables

Kerryx

Well-known Member
Joined
May 6, 2016
Messages
773
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi all,
tried the following to sort the excel table but all Total column does is flash ( in a millisecond) and then immediately reverts to original order and the Names in the name column move around to different cells in the column and if you run code again names move around in the name column, any ideas where i might be messing up.
First time using tables for this stuff rather than sheets and ranges

VBA Code:
Sub Sort()
Dim ws As Worksheet
Set ws = ActiveSheet
With ws.ListObjects("LB_1").Sort
        .SortFields.Clear
        .SortFields.Add Key:=Range("LB_1[Total]"), Order:=1
         .Header = xlYes
        .Apply
    End With
End Sub


Rollover API source 2026(1).xlsm
ABCDEFGHIJKLMNOPS
1PositionEntry No.NameTotalTotal +/- BonusJulAugSeptOctNovDecJanFeb MarAprMayGD
211Jim84486409987123811321141139500102
322Andy82183409578115931151121081050060
433Frank771767080801117314010485980014
544Terry7507460818710862117109899700-63
655Joe801804087939366147115105950057
Sheet1
Cell Formulas
RangeFormula
A2:A6A2=IF(C2<>"",COUNTA($C$2:C2),"")
B2:B6B2=Pt_By_Lg[@[Entry No.]]
D2:D6D2=Pt_By_Lg[@Total]
E2:E6E2=Pt_By_Lg[@[Total +/- Bonus]]
F2:F6F2=IF(C2="","",SUMPRODUCT(SUMIF(TablesAll[Team],Name[@[Premier1]:[League 2.4]],Month[Jul])))
G2:G6G2=IF($C$2="","",SUMPRODUCT(SUMIF(TablesAll[Team],Name[@[Premier1]:[League 2.4]],Month[Aug])))
H2:H6H2=IF($C$2="","",SUMPRODUCT(SUMIF(TablesAll[Team],Name[@[Premier1]:[League 2.4]],Month[Sept])))
I2:I6I2=IF($C$2="","",SUMPRODUCT(SUMIF(TablesAll[Team],Name[@[Premier1]:[League 2.4]],Month[Oct])))
J2:J6J2=IF($C$2="","",SUMPRODUCT(SUMIF(TablesAll[Team],Name[@[Premier1]:[League 2.4]],Month[Nov])))
K2:K6K2=IF($C$2="","",SUMPRODUCT(SUMIF(TablesAll[Team],Name[@[Premier1]:[League 2.4]],Month[Dec])))
L2:L6L2=IF($C$2="","",SUMPRODUCT(SUMIF(TablesAll[Team],Name[@[Premier1]:[League 2.4]],Month[Jan])))
M2:M6M2=IF($C$2="","",SUMPRODUCT(SUMIF(TablesAll[Team],Name[@[Premier1]:[League 2.4]],Month[Feb])))
N2:N6N2=IF($C$2="","",SUMPRODUCT(SUMIF(TablesAll[Team],Name[@[Premier1]:[League 2.4]],Month[Mar])))
O2:O6O2=IF($C$2="","",SUMPRODUCT(SUMIF(TablesAll[Team],Name[@[Premier1]:[League 2.4]],Month[Apr])))
P2:P6P2=IF($C$2="","",SUMPRODUCT(SUMIF(TablesAll[Team],Name[@[Premier1]:[League 2.4]],Month[May])))
S2:S6S2=Pt_By_Lg[@GD]
Cells with Conditional Formatting
CellConditionCell FormatStop If True
I3:I6Cell Valuetop 1 valuestextNO
F2:F6Cell Valuetop 1 valuestextNO
G2:G6,H2:P2,O3:P6Cell Valuetop 1 valuestextNO
H3:H6Cell Valuetop 1 valuestextNO
J3:J6Cell Valuetop 1 valuestextNO
K3:K6Cell Valuetop 1 valuestextNO
L3:L6Cell Valuetop 1 valuestextNO
M3:M6Cell Valuetop 1 valuestextNO
N3:N6Cell Valuetop 1 valuestextNO
 
any ideas where i might be messing up
Yes. Ditch the @s.

@ means that no matter how you sort the table the value in row # 2 will be taken from row # 2 in the source table, the value in row 3 - from row 3, etc.
So you need another way of getting these values otherwise every time you sort them you will get the original values again.
If the Value are connected with the Name, use match or lookup to get them.
 
Upvote 0
Solution

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top