VBA Code for Sorting by Subset

jardenp

Active Member
Joined
May 12, 2009
Messages
373
Office Version
  1. 2019
  2. 2016
  3. 2013
  4. 2011
  5. 2010
Platform
  1. Windows
I have reports that are formatted like so:

A:A

Vendor: [Vendor A]
Item 1
Item 2
Item 3
Vendor: [Vendor B]
Item 1
Item 2
Vendor: [Vendor C]
Item 1
...
1) the number of items per vendor varies
2) the vendor lines are always in bold
3) the item lines always begin with "??-" (as it would be phrased in the Find function)

I want to automatically sort the items in numerical order by vendor. How can I include this in my macro?
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Setup a 2nd column to put the vendor name in.

so that's column A
In B1 put put Vendor1's name
In B2 put the formula
=IF(LEFT(A2,3)="??-",B1,A2)
Fill down

Now you have each vendor's name in column B.
highlight and copy column B
paste special - values

Now sort by column B.
 
Upvote 0
Thanks

Thanks for the reply jonmo1. I think I understand what your doing and I think that would work if I was to manipulate the sheet in front of me, but how would that translate into VBA code? I'm making a macro for a coworker, so I won't be able to manipulate anything manually--I need it all to work through the single macro.

I do appreciate your reply and if you could help with the VBA code, that would be great too!

JP
 
Upvote 0
Re: Thanks

The macro recoreder is your friend...

Click Tools - Macro - Record New Macro
Give it a name and click OK

Now do the steps described above by hand.

Click Tools - Macro - Stop Recording.


You now have a macro that should get you started.
You can copy / paste that resulting code into the thread here, and it can likely be cleaned up a bit.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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