Macro to sort two different tables in same sheet

ExlN00b

New Member
Joined
Nov 6, 2021
Messages
5
Office Version
  1. 365
Platform
  1. Windows
I have a sheet with two separate tables - need to sort them by Column B, separately. The VBA I have combines the two tables and sorts them into one table.

Need:
  1. Sort Column B from "1" to the last number in the set (example: Table 1 from 1-6; Table 2 from 1-4)
  2. The only constant is "1" to indicate the start of the table
Any assistance or pointing to the right direction would be great!

Sub PO_CSV_Multi()
'
' PO_CSV_Multi Macro
'
Columns("E:F").Select
Selection.Delete Shift:=xlToLeft
Columns("I:J").Select
Selection.ColumnWidth = 11.38

Range("B18", Range("J" & Rows.count).End(xlUp).Address).Sort Key1:=[b3], _
Order1:=xlAscending, Header:=xlNo

End Sub
 

Attachments

  • MacroPO.JPG
    MacroPO.JPG
    163.5 KB · Views: 45
If we give you a solution per your requirements then I expect you won't get the maximum benefit since it looks like you are manually adding formulas to column J.
It would be better if you posted the actual source csv import without having any manual manipulation done to it.

Then show us what you want as a result and perhaps how you are going to use the data. I would normally be aiming for a database style output that only has the detail lines and not the total lines and also has the order hearder details on each line but that it is not what you are asking for.

Based on your current request you could simply apply a filter. Product descripion is not blank and cost is blank. Then delete all the visible rows.
That could be converted to a macro. But that would leave you still having to put in formulas for each PO if you want to stick to your current format.
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hello! Checking if you’re able to assist me with the template to be able to format and sort different sections separately? Thank you so much!
Template is ready . I will share on night .
 
Upvote 0
Something like start in B18; sort rows 18 - 25
If that is done, the result would be as below. Is that what you want?
.. or should the "Detail a" and "Detail b" rows remain with Product # 101034 etc?

1642483806860.png
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

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