Solved

Sorting a column

Posted on 2012-12-27
3
272 Views
Last Modified: 2012-12-28
EE Pros,

I have a simple graphic that depicts priority based on two factors.  I need a macro that looks at a helper cell (column) and determines "priority" (high to low) and properly place a set of sequencial rows in the proper order (highest priority first).  I have attached a worksheet so you can see exactly what I'm trying to accomplish.

Thank you in advance,

B.
Risk-priority-graphic.xlsm
0
Comment
Question by:Bright01
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
redmondb earned 500 total points
ID: 38725767
Hi, Bright01.

Please see attached. The code (below) uses the Helper Cells column to determine how many rows are in the table - the last row is considered to be the one before the first blank cell.
Option Explicit

Sub Prioritise()
Dim xLast_Row As Long

Sheets("Risk_Return").Activate

Range("E6").End(xlDown).Select

xLast_Row = ActiveCell.Row
Range("A7").Select

If xLast_Row = Cells.Rows.Count Then
    MsgBox ("No data found - run cancelled.")
    Exit Sub
End If

With Sheets("Risk_Return").Sort
    .SortFields.Clear
    .SortFields.Add Key:=Range("E7:E" & xLast_Row), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
    .SetRange Range("A6:E" & xLast_Row)
    .Header = xlYes
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
End With

Range("A7") = "1"
Range("A7").AutoFill Destination:=Range("A7:A" & xLast_Row), Type:=xlFillSeries

End Sub

Open in new window

Regards,
Brian.Risk-priority-graphic-V2.xlsm
0
 

Author Closing Comment

by:Bright01
ID: 38726526
Brian,

"Beautiful"!!!  Thank you very much.

B.
0
 
LVL 26

Expert Comment

by:redmondb
ID: 38726553
Thanks, Bright01!
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
excel file 5 47
AutoFilter Delete not keeping Headers? 2 12
Importing csv to excel - text formating 14 21
onOpen 14 41
INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now