Select cell based on value and highlight to the last column with data

thepeej

New Member
Joined
Feb 22, 2022
Messages
2
Office Version
  1. 365
I have data that includes merged cells (both vertically and horizontally) with various "Total" rows summarizing different levels of details. For a particular column, I need to find each row that says "Total" and highlight that cell and all cells to the end of that row, but I don't want to highlight to the last column in Excel (just to the end of my data) and I don't want to highlight to the left (because the column to the left is vertically merged).

Image attached. the blue, green, and pink lines are what I'm trying to achieve. (Tried to paste Mini-sheet but add-in not working on work computer).

Thanks!
 

Attachments

  • Annotation 2022-02-23 002213.png
    Annotation 2022-02-23 002213.png
    49 KB · Views: 11

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
The image did not show what last column is.
I assum its column I
Try 3 different conditioning formatting formulas with 3 different colours
Like this:
Stay in cell A1:
Level 1: "Total" in column B
Code:
=AND($B1="Total",COLUMN(A1)>=2,COLUMN(A1)<COLUMN($I:$I))
Level 2: "Total" in column C
Code:
=AND($C1="Total",COLUMN(A1)>=3,COLUMN(A1)<COLUMN($I:$I))
Level 3: "Total" in column E
Code:
=AND($E1="Total",COLUMN(A1)>=5,COLUMN(A1)<COLUMN($I:$I))





Book1
ABCDEFGHI
1
2
3
4
5
6
7Total
8Total
9Total
10
11Total
12
13Total
14
15
16
17
18Last column
19column I
Sheet6
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A1:I15Expression=AND($B1="Total",COLUMN(A1)>=2,COLUMN(A1)<COLUMN($I:$I))textNO
A1:I15Expression=AND($C1="Total",COLUMN(A1)>=3,COLUMN(A1)<COLUMN($I:$I))textNO
A1:I15Expression=AND($E1="Total",COLUMN(A1)>=5,COLUMN(A1)<COLUMN($I:$I))textNO
 
Upvote 0
Thanks Bebo, that would work but i was hoping for a VBA solution. This is a report i receive weekly that i do a number of other formatting functions to via VBA...would like to add this to the existing code.
 
Upvote 0
VBA solution

VBA Code:
Option Explicit
Sub test()
Dim Lc&, Rng As Range, cell As Range
Lc = Cells(1, Columns.Count).End(xlToLeft).Column ' Last column
Set Rng = Range(Cells(1, 1), Cells(Cells(Rows.Count, "B").End(xlUp).Row, Lc))
    For Each cell In Rng
        If cell.Value Like "Total" Then
            With cell.Resize(, Lc - cell.Column)
                Select Case cell.Column
                    Case Is = 2
                        .Interior.ColorIndex = 41
                    Case Is = 3
                        .Interior.ColorIndex = 34
                    Case Is = 5
                        .Interior.ColorIndex = 40
                End Select
            End With
        End If
    Next
End Sub

Book1
ABCDEFGHI
1ABCDEFGHI
2
3
4
5
6
7Total
8Total
9Total
10
11Total
12
13Total
14Total
15
16
17
18Last column
19column I
20
21
22
Sheet1
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,636
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top