Solved

EXCEL Conditional Formatting: Define a row range in which to identify the highest value in a column

Posted on 2014-09-06
6
138 Views
Last Modified: 2014-09-08
I have an Excel spreadsheet consisting of groups of rows. Each row group is defined by the matching values in Column A. For example:

......................A...........................B
 1..........Group Name 1............Data1
 2..........Group Name 1............Data2
 3..........Group Name 1............Data3
 4..........Group Name 1............Data4
 5..........Group Name 2............Data5
 6..........Group Name 2............Data6
 7..........Group Name 2............Data7
 8..........Group Name 3............Data8
 9..........Group Name 3............Data9
 10........Group Name 4............Data10
 11........Group Name 4............Data11
 12........Group Name 4............Data12

I'd like to use Conditional Formatting to highlight the highest value in Column B within each row group, but I'm not able to determine a formula to identify the range of each row group.

How would this be done? Thanks for your help.

Dimarc67
Frederick, MD
0
Comment
Question by:Dimarc67
[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
  • 3
  • 3
6 Comments
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40307959
If you don't have a large number of groups (or perhaps even if you do) you could create Named Ranges in column B for each group and add "top or bottom" Data Validation for each one of them as I've done in the attached workbook.

The picture below shows the addition of the first group's Data Validation. It may be confusing but I gave the Named Ranges the name of the group even though the named range is in col B. After you enter the name of the named range in the data validation window it will be change to the actual cell range when you look at it again.
DVQ-28513050.xlsm
0
 
LVL 4

Author Comment

by:Dimarc67
ID: 40307983
Thanks, Martin.  I also considered your solution, but I neglected to mention that the spreadsheet is 4000 rows, and is a weekly generated report, so an automated solution is required.

Putting Conditional Formatting aside, can you determine a cell formula that is able to discern the member rows of each group, and then within the group determine the highest value in column B?
0
 
LVL 47

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 40308032
OK then call this macro after the updating is done. You may have to delete the existing named ranges and data validation first. And I'm not a formula expert but I doubt you can do it via one data validation formula.

Sub SetUp()
Dim lngLastRow As Long
Dim lngRow As Long
Dim strGroup As String
Dim lngGroupStartRow As Long
Dim intGroup As Integer

    lngLastRow = Range("A65536").End(xlUp).Row
    lngGroupStartRow = 1
    strGroup = Range("A1").Value
    
    For lngRow = 2 To lngLastRow + 1
        If Range("A" & lngRow).Value <> strGroup Then
            Range("B" & lngGroupStartRow & ":B" & lngRow - 1).Select
            intGroup = intGroup + 1
            ActiveWorkbook.Names.Add Name:="Group" & intGroup, RefersToR1C1:="=Sheet1!R" & lngGroupStartRow & ":R" & lngRow - 1 & "C2"
            Selection.FormatConditions.AddTop10
            Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
            With Selection.FormatConditions(1)
                .TopBottom = xlTop10Top
                .Rank = 1
                .Percent = False
            End With
            With Selection.FormatConditions(1).Interior
                .PatternColorIndex = xlAutomatic
                .Color = 65535
                .TintAndShade = 0
            End With
            strGroup = Range("A" & lngRow).Value
            lngGroupStartRow = lngRow
        End If
    Next
End Sub

Open in new window

0
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!

 
LVL 4

Author Closing Comment

by:Dimarc67
ID: 40308038
Thanks, Martin.  A macro is something I really hadn't even considered yet, and probably the best solution.  Writing code for me was above and beyond.  :-)
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 40308041
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0
 
LVL 4

Author Comment

by:Dimarc67
ID: 40310786
Actually found the way to do this with an array formula that can be used in Conditional Formatting, or within a cell.  (Credit to CRondao on StackOverflow.com.)

=MAX(IF(A1=$A$1:$A$12,$B$1:$B$12))

At first, this seemed incorrect because it was returning the highest value in all of column B instead of within each group.  However, to enter an array formula, you have to press Ctrl-Shift-Enter after placing the formula in the cell (instead of just Enter).  Once that's done, the formula displays in the formula bar within braces ({ }) to indicate that it's an array formula.

Once it was entered into cell C1 as an array formula, I then copied it to all column C cells normally, and each row then correctly displayed the highest column B value within each name group.
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

738 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