sorting using letters , but not alphabetically.

R

Romileyrunner1

Hi I want write a macro to sort a spreadsheet with the rows being ordered
from a particular collumn which contain the following letters: W, SA, SA+, ST
and blank cells. I need the rows to be sorted in that order from top to
bottom. I.E. a;; the `W` rows first, all the ` SA` rows next etc.

Now, I know I could create a collumn next to it with perhaps a vlookup
reference of say W=1. SA =2 etc, and then sort on that instead, but belive it
or not, I`m almost out of collumns (it`s a big spreadsheet) and also some of
my other refences might be affected if I go and plonk another collumn in now.
Any ideas?
Thanks guys
RR1
 
B

Bernie Deitrick

Romileyrunner1,

Enter your values in the desired order in a block of cells, and select those cells. Then use Tools
/ Options.... Custom Lists Import OK.

Then select your data, use Data / Sort... Options.... and select your new list from the available
lists.

HTH,
Bernie
MS Excel MVP
 
P

Pete_UK

You could do a multiple Find & Replace on that column in your macro to
replace ST with 4, SA+ with 3, SA with 2 and W with 1, then do your
sort, and then re-apply your Find & Replace backwards if you want to
keep those codes.

Hope this helps.

Pete
 
L

Luke M

Under Tools-Options - Lists, you can create a Custom List telling XL how you
want certain things ordered. This will create a custom list.

Then, if you were to go to Data - Sort, under Options, you can choose which
custom list you want to sort by. In VB, this will end up looking something
like this:

Selection.Sort Key1:=Range("C12"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=6, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

The key part is "OrderCustom:=6" as this is saying to use the 6th Custom
List. You will need to modify this to fit your actual settings.
 
M

Mike H

Hi,

You need to build a custom list like this

Within Excel, click Tools and click Options.
Select the Custom Lists tab.
Under Custom Lists, verify that NEW LIST is highlighted.
In the List Entries field, start typing in your list elements in the order
they should be sorted. Make sure you press Enter after each element.
Once you have typed in all the elements, press Add.
Click OK.

Now select your data and then

Data, sort, Custom and select the list you created and sort your data

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top