Solved

Sorting a column

Posted on 2012-12-27
3
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

688 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