Results 1 to 3 of 3

Ranking data based on set criteria

Threaded View

  1. #1
    Registered User
    Join Date
    04-16-2013
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    29

    Ranking data based on set criteria

    Hi,

    I am trying to create a macro that ranks my data based on criteria in 3 different fields.

    For each state (column A) for each month (column C) if Column L = "Y" then rank based on values in column J in column Q.

    eg. for NSW, I want to see the revenue ranked highest to lowest for each month with the rank placed in column Q.

    I have attached some sample data, and the code is below.

    I have not been able to get the macro to work (I'm sure those with knowledge could pin point the problem straight away) and that is only based on trying to get the all of the data ranked based on state, without the other criteria needed.

    Any help would be much appreciated.

    Book1.xlsx

    Sub Rank_By_State()
    Dim lastRw, firstRw, nxtRw As Integer
    Dim myState As Range
    'Determine last row in table
     lastRw = Range("A" & Rows.Count).End(xlUp).Row
    'Intialize Row Counter
      firstRw = 2
    'Loop through range looking for change in Column A
       For Each myState In Range("A2:A" & lastRw)
    'Increment last row counter
        nxtRw = nxtRw + 1
    'Build and Place formula at change of value
         If myState <> myState.Offset(1, 0) Then
          Range("Q" & firstRw & ":Q" & firstRw + nxtRw - 1).Formula = _
           "=RANK(RC[-7],R" & firstRw & "A3:R" & firstRw + nxtRw - 1 & "A3)"
    'Set start row for next set of values
             firstRw = firstRw + nxtRw
    'Reset last row counter
             nxtRw = 0
         End If
       Next
    End Sub
    Last edited by Panfergrrl18; 01-09-2014 at 07:58 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Ranking Based on Three Criteria
    By annie82 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 05-28-2013, 01:21 AM
  2. [SOLVED] Finding Nth ranking value based on multiple criteria
    By scaffdog845 in forum Excel Formulas & Functions
    Replies: 18
    Last Post: 04-26-2013, 01:00 PM
  3. [SOLVED] Ranking based on 2 criteria with named range
    By Webbers in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 04-19-2012, 07:21 AM
  4. Excel 2007 : Ranking Based on Three Criteria
    By CRIMEDOG in forum Excel General
    Replies: 4
    Last Post: 02-09-2012, 08:18 PM
  5. Ranking based on certain criteria?
    By Ahmad Adha Ali in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-18-2005, 04:51 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1