Document will not Sort properly

Brian Feth

New Member
Joined
May 21, 2017
Messages
39
Office Version
  1. 2021
Platform
  1. Windows
Windows 11, Excel 2021; I have a problem with the Sort function. I put together a macro that takes the .csv bank account information and compiles into one document for manipulation. The columns are; Date, Transaction, Debit, Credit, Vendor_1 (e.g. “Home Depot, Costco, etc.), Catigory_1 (e.g. Medical, Food, etc.) , and Description (the banks description of the exchange). The problem; it won’t Sort. When I Sort by Vendor_1 it goes through a sort process but the result is garbled. I end up with 1 to 4 entries of one record over writing the actual entries followed by several correct rows followed by an several misplaced alternating repetitive rows. The document has ~500 rows.

It all seems pretty straight forward but it doesn’t work. Any ideas? Help is always appreciated.

Sub SortByVendor()
WBName = Range("N1").Value
Range("N2").Value = Range("P2").Value
LedgerName = Range("N2").Value
Workbooks(WBName).Worksheets(LedgerName).Activate

Range("C5").Select
Selection.End(xlDown).Select
TopRange = Selection.Row
Set SortRange = Range("C" & TopRange & ":" & "J1000")
Set KeyRange = Range("H" & TopRange & ":" & "H1000")

ActiveWorkbook.Worksheets(LedgerName).Sort.SortFields.Clear
ActiveWorkbook.Worksheets(LedgerName).Sort.SortFields.Add2 Key:=KeyRange, _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal

With ActiveWorkbook.Worksheets(LedgerName).Sort 'DataOption1 Optional XlSortDataOption
.SetRange SortRange
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
'.SortMethod = xlPinYin
.XlSortDataOption = 0
.Apply
End With
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Show us what your data looks like include row and column references.

PS: Please update your Excel Version IN YOUR ACCOUNT PROFILE as Peter asked you to do in your last 2 threads.
 
Upvote 0
I apologize for the misunderstanding. I didn't realize I was being asked to update my profile, which I have now done. I have always included “Windows 11, Excel 2021” at the beginning of my questions thinking that was sufficient.
 
Upvote 0
Thanks for doing that.
You didn't provide an image of what your data looks like. We need to see how your data is shaped and located on the sheet.
 
Upvote 0
Yes, the problem seems to have corrected itself! I have no idea why and I don't think there is any reason to pursue the issue until a can determine what's going on. I'll mark this as solve for now to avoid wasting any more of anyone's time. I hope that I is the right procedure.
 
Upvote 0
I'll mark this as solve for now to avoid wasting any more of anyone's time. I hope that I is the right procedure.
It’s more helpful not to mark a question as solved when there’s no solution. A future reader who has experienced and resolved the same issue might share their solution.
Unless you’ve answered your own question or received an answer that resolves the problem, please avoid marking a post as the solution.
I’ve removed the solution mark for now, and no further action is needed on your part.
 
Upvote 0

Forum statistics

Threads
1,225,775
Messages
6,186,975
Members
453,393
Latest member
djangoframe

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