How do I sort numbers based on last two digits?

T

The Wallaby

I am working on a hospital project. Casenotes are stored by a 3 dual digit
system eg. 23 44 67 with casenotes ending in ** ** 68 and ** ** 66 stored
adjacent. Get it? I have a load of notes to look up so I need to sort out the
casenote numbers I have by the last two digits in order to simplify the
manual search for the notes. Is there any way I could program the Excel list
I have to sort the last two digits of the casenote numbers into numerical
order?
 
B

ben

Wallaby,

The following code assumes all your data is in one list and the case
notes are in the first row, and all data is on sheet1

sub sort()
nurec = sheet1.usedrange.rows.count
for t = 1 to nurec
for y = 1 to nurec
casno = right(cells(y,1),2)
casnonex = right(cells(y+1,1),2)
if casnonex > casno then goto nexty
rows(trim(str(y))).copy
rows(trim(str(nurec+6))).select
activesheet.paste
rows(trim(str(y+1))).copy
rows(trim(str(y))).select
activesheet.paste
rows(trim(str(nurec+6))).copy
rows(trim(str(y+1))).select
activesheet.paste
rows(trim(str(nurec+6))).clear
nexty:
next y
next t
end sub
note this sub is completely untested and i may have misunderstood your
criteria, run on a backup copy first
 
F

Fredrik Wahlgren

The Wallaby said:
I am working on a hospital project. Casenotes are stored by a 3 dual digit
system eg. 23 44 67 with casenotes ending in ** ** 68 and ** ** 66 stored
adjacent. Get it? I have a load of notes to look up so I need to sort out the
casenote numbers I have by the last two digits in order to simplify the
manual search for the notes. Is there any way I could program the Excel list
I have to sort the last two digits of the casenote numbers into numerical
order?

Assuming that your casenotes are in column A, enter =RIGHT(A1,2) in colmun B
and drag downwards. Select columns A and B and select Data|Sort. Sort on
column B.

/Fredrik
 

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