Link to home
Start Free TrialLog in
Avatar of 3wits
3witsFlag for United States of America

asked on

How do I highlight columns A thru P on a row that contains certain keywords in column C.

I have a spreadsheet that contains subtotal rows.  In column C,  the words "100% Total" or "90% Total" or 75% Total" etc., appear.  I want to find the rows that contain the word Total in column C, then I want to highlight Columns A thru P in those particular rows.  I want to highlight with 25% gray.
Avatar of dlmille
dlmille
Flag of United States of America image

The "truth" test is =FIND($C1,"Total")>0

So if the word Total exists anywhere in column C row 1, then you get true as a result, and thus the condition can apply formats to $A1:$P1.

I created a test for you, for the first 18 rows, demonstrating this.  You can just copy the A:P formats down as far as you'd like.

The trick is the $ in the FIND commandand the $ settings in the "Applies To, to ensure that evertyhing moves from row to row andn stays fixed in the columns that are set.

So click in C1, and set the conditional formatting using =FIND($C1,"Total")>0, then manage your conditional formatting and ensure Applies To is $A1:$P1.  Then you can copy formats down as long as you want (copying A1:P1 over the dataset you want this formatting for).

Her's a picture on how it was setup:

 User generated image
See attached,

Dave
highlight-Total-A-P-r1.xlsx
Avatar of 3wits

ASKER

Thanks Dave.
I tried it, IT WORKS, but we need to make an adjustment.  The content in C will say "100% Total" or "90% Total" or" 75% Total".  Therfore, the rows that I want highlighted contain the word "Total" but also has other text. It's like we need a wildcard or something. Can you make an adjustment for this.

ALSO, is there a way to have it insert a blank line under the row we just highlighted?

This is what I'm doing.  I'm writing a macro that
     1)sets filter
     2) sort A
     3) sort C
     4) subtotal several columns based on Column C
     5) remove filters

 I would love to add these 2 steps after #4 above
     5) highlight the subtotal rows
     6) insert a blank line under the subtotals

The reason for this macro:  Percentages will change in column C.  The macro is needed for it to move to its correct location.

Thanks.
 
test--8-5-11.xlsm
Before we go there, first, let's take a look at the formula for conditional formatting:

=FIND($C1,"Total")>0 <- My bad, it should be rephrased to where the FIND_TEXT is the first parameter.

It should be =FIND("Total",$C1)>0

This means that if the text Total is ANYWHERE in the string, the conditional setting would be set to TRUE.

See examples in the attached.

highlight-Total-A-P-r2.xlsx
Avatar of 3wits

ASKER

Thanks - that works.  Now how do I get that in my macro?
For your second part to insert row, see code at bottom, thus:
 
Application.EnableEvents = False
    
    Set fRange = Range("C:C").Find(what:="Total", LookIn:=xlValues, lookat:=xlPart)
    
    If Not fRange Is Nothing Then
        firstAddress = fRange.Address
        Set insertRow = fRange.Offset(1, 0)
        Do
        
            Set fRange = Range("C:C").FindNext(fRange)
            If Not fRange Is Nothing Then
                Set insertRow = Union(insertRow, fRange.Offset(1, 0))
            End If
        Loop While Not fRange Is Nothing And firstAddress <> fRange.Address
    
        insertRow.EntireRow.Insert
    End If
    Application.EnableEvents = True
    Range("A1").Select

Open in new window


See attached file revision with macro changes.

Enjoy!

Dave
test--8-5-11.xlsm
Avatar of 3wits

ASKER

Thank you so much Dave.  We are getting close.  It worked.  I changed two percentages, CTRL-t and it worked.  However, I changes two percentages again and I got an error message.

Deb
ASKER CERTIFIED SOLUTION
Avatar of dlmille
dlmille
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 3wits

ASKER

I'm sorry.  You are correct.  I'm not sure what I was doing the first time.  Thank you so much for your help.  Your advice has been excellent.
Avatar of 3wits

ASKER

This help was great