Challenging Excel Question

P

paranous

Version: 2008
Operating System: Mac OS X 10.5 (Leopard)
Processor: Intel

Hello,

I am unsure how to do the following in Excel. Here's what I have and what I'd like to do:

I have a list of universities and associated data (e.g. number of faculty, research award funding, etc.). It's easy for me to create the columns and sort by the criterion I am interested in, in order to get a ranking by that criterion. But what I'd like also to do is to create rankings based on those criterions. So, for example, I'd like to have column that simply lists the rank order of the universities when I sort by criterion A. I have figured out how to do this. But I want to be able to do this with EACH criterion (e.g. A, B, C,) without disrupting the rank order for the previous criterion. Why I want to do this is because i then want a final field that sums the rank number for each criterion to get a meta-ranking of the universities (e.g. a Bordq Count). In other words, I want to be able to sort the university list by different criterion (1 at a time) and be able to retain the rank numbers for each sorting, without them changing when I re-sort based on the next criterion. Any ideas? I know it's a bit complicated - Here is a simple example using just 3 criterion:

Institution Faculty # Grants Received ($) Endowment ($)
Alpha 234 10,567 600
Beta 569 9,876 857
Chi 71 7,952 1175
Delta 1198 2408 1897

It's straightforward to sort by criterion. I can even add a Ranking column that will provide the correct ranking for each institution, depending on the column sorted. However, every time one re-sorts based on another criterion, this ranking changes as well, meaning that I can take the rank order for each criterion and sum them up. I could simply cut-and-paste the results for every sort, but I want this to update automatically.

Any thoughts? Thanks!

Jay
 
P

paranous

In the penultimate sentence, I meant to write "meaning that I CANNOT take the rank order for each criterion and sum them up..."

Sorry.

Jay
 
L

Laroche J

Version: 2008
Operating System: Mac OS X 10.5 (Leopard)
Processor: Intel

Hello,

I am unsure how to do the following in Excel. Here's what I have and what I'd
like to do:

I have a list of universities and associated data (e.g. number of faculty,
research award funding, etc.). It's easy for me to create the columns and sort
by the criterion I am interested in, in order to get a ranking by that
criterion. But what I'd like also to do is to create rankings based on those
criterions. So, for example, I'd like to have column that simply lists the
rank order of the universities when I sort by criterion A. I have figured out
how to do this. But I want to be able to do this with EACH criterion (e.g. A,
B, C,) without disrupting the rank order for the previous criterion. Why I
want to do this is because i then want a final field that sums the rank number
for each criterion to get a meta-ranking of the universities (e.g. a Bordq
Count). In other words, I want to be able to sort the university list by
different criterion (1 at a time) and be able to retain the rank numbers for
each sorting, without them changing when I re-sort based on the next
criterion. Any ideas? I know it's a bit complicated - Here is a simple example
using just 3 criterion:

Institution Faculty # Grants Received ($) Endowment ($)
Alpha 234 10,567 600
Beta 569 9,876 857
Chi 71 7,952 1175
Delta 1198 2408 1897

It's straightforward to sort by criterion. I can even add a Ranking column
that will provide the correct ranking for each institution, depending on the
column sorted. However, every time one re-sorts based on another criterion,
this ranking changes as well, meaning that I can (not) take the rank order for each
criterion and sum them up. I could simply cut-and-paste the results for every
sort, but I want this to update automatically.

Any thoughts? Thanks!

Jay

Hi Jay

Try this Applescript. Enter your own values at the beginning.

It will sort the whole table based on one data column, fill a corresponding
ranking column with numbers 1 to the number of records, then sort according
to the next column and so on. Since the sort action includes the ranking
columns the ranks move with their respective data.

Save the script, as an application, in ~/Library/Scripts/Applications/Excel.
It will appear in the menu bar under the big S, which you may need to show
using the AppleScript Utility (in Applications/AppleScript)

JL
Mac OS X 10.4.11
Office v.X 10.1.9



-- Sort many columns independently and memorize the sort order of each one
-- Jean Laroche 2009

-- Change the following values according to the table to sort
set FirstDataColumn to 1 -- "A"
set LastDataColumn to 5 -- "E"
set SortOrders to "11211" -- 1 for ascending, 2 for descending
set RankColumn to 7 -- "G"
set MetaTotalColumn to 12 -- "L"
set HeaderRow to 3

tell application "Microsoft Excel"
Activate

-- set various global ranges
set UR to UsedRange of ActiveSheet
set LastRow to Row of last Cell of UR
set TopLeftData to Address of Row HeaderRow of Column FirstDataColumn
set BottomRightUR to Address of last Cell of UR
set SortingArea to TopLeftData & ":" & BottomRightUR

-- sort each one of the data columns
repeat with C from 1 to (LastDataColumn - FirstDataColumn + 1)

-- determine the sort order for the column to sort, then sort
-- previous ranks are also sorted
set SortOrder to character C of SortOrders as integer
Sort Range SortingArea Key1 Column (C + FirstDataColumn - 1) ¬
Order1 SortOrder Header xlYes OrderCustom 1 ¬
Orientation xlTopToBottom without MatchCase

-- establish the ranges required to memorize the sort order
set RankColumnStart to Address of Cell RankColumn of ¬
Row (HeaderRow + 1)
set RankColumnFill to RankColumnStart & ":" & ¬
(Address of Cell RankColumn of Row (HeaderRow + 2))
set RankColumnFillAll to RankColumnStart & ":" & ¬
(Address of Cell RankColumn of Row LastRow)

-- fill the sort order range with consecutive numbers
Select Range RankColumnStart
set FormulaR1C1 of ActiveCell to "1"
set FormulaR1C1 of (Offset RowOffset 1) of ActiveCell to "2"
AutoFill Range RankColumnFill Destination Range RankColumnFillAll ¬
Type xlFillDefault
set RankColumn to RankColumn + 1

end repeat

-- sort the meta totals (the formulas must be previously entered)
Sort Range SortingArea Key1 Column MetaTotalColumn Order1 xlAscending ¬
Header xlYes OrderCustom 1 Orientation xlTopToBottom ¬
without MatchCase

-- select the top left cell of the table
Select Range TopLeftData

end tell
 

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