multiple sort in vba

Tej92

Board Regular
Joined
Sep 27, 2022
Messages
73
Office Version
  1. 365
Platform
  1. Windows
Hello everyone, I'm trying to sort the "data" sheet by column G then I and it's not working

the code is within another SUB

essentially I'm send data to another sheet with a command button and if there are multiples it will delete them leaving only one and i want to keep the most recent one, column I is the data submission date and column G is the value that needs sorting.
i already have the delete multiple code working but it deleted the latest value added.


With wbLocal.Worksheets("data").Sort
.SortFields.Add Key:=wbLocal.Worksheets("data").Range("G1"), Order:=xlAscending
.SortFields.Add Key:=wbLocal.Worksheets("data").Range("I1"), Order:=xlAscending
.SetRange Range("A1:I50")
.Header = xlYes
.Apply
End With


thanks
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
managed to sort it out by modifying to the following formula
thanks to everyone who had a look and tried.

wbLocal.Worksheets("data").Sort.SortFields.Clear
wbLocal.Worksheets("data").UsedRange.Sort Key1:=wbLocal.Worksheets("data").Range("G1"), Key2:=wbLocal.Worksheets("data").Range("I1"), Header:=x1Yes, order1:=xlAscending, Order2:=xlDescending
 
Upvote 0
Solution

Forum statistics

Threads
1,215,262
Messages
6,123,938
Members
449,134
Latest member
NickWBA

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