Sort Question

misho

New Member
Joined
Sep 12, 2002
Messages
1
I have a list of prioritized items in Excel 98. In the first column is the priority number, 1 through x. sometimes I will need to change a priority number, say make a new item that is priority 1, making the old priority number 1 into 2, 2 into 3, etc. How can this be done?
 

Some videos you may like

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Damon Ostrander

MrExcel MVP
Joined
Feb 17, 2002
Messages
4,239
Hi Misho,

Well, here is one way. Simply select the cells containing the old priority numbers and run the macro below. It will add 1 to each of the selected cells.

Sub Add1()
For Each Cell In Selection
Cell.Value = Cell.Value + 1
Next Cell
End Sub

If you don't know how to install a VBA macro, it's really
quite easy. Just follow these steps:

1) Go to the Visual Basic Editor (VBE). Do this from Tools >
Macro > Visual Basic Editor (or simply keyboard Alt-TMV)

2) In the VBE create a new Macro Module: Insert > Module.
An empty code window pane will appear (Alt-IM).

3) Paste the code into this window. The macro or function is
now available for use from Excel. If it is a Function type
macro you can immediately use it as an Excel function. If
it is a Sub (subroutine) type macro you can run it from
the Excel Tools > Macro menu (Alt-TMM).
 

Juan Pablo González

MrExcel MVP
Joined
Feb 8, 2002
Messages
11,959
If you can use an extra column, you could use this formula.

Say for example that your priorities are in A1:A10, then in B1:B10 put this:

=RANK(A1,$A$1:$A$10,1)+COUNTIF($A$1:A1,A1)-1
 

Watch MrExcel Video

Forum statistics

Threads
1,118,055
Messages
5,569,936
Members
412,299
Latest member
agentless
Top