VBA Select Entire Row when cell is selected

bamaisgreat

Well-known Member
Joined
Jan 23, 2012
Messages
821
Office Version
  1. 365
Platform
  1. Windows
Do any you have away I can change the code below to have the entire row change to red instead of just the selected cell? Thanks as always

Code:
 Cells.Select
    Selection.FormatConditions.Add Type:=xlTextString, String:="(OBSOLETE", _
        TextOperator:=xlBeginsWith
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    ' adam test
    Dim test As Integer
    test = Selection.Row
    ' end test
    
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try
Code:
With Selection.EntireRow.FormatConditions(1).Interior
 
Last edited:
Upvote 0
Yongle, I tried adding the code you mentioned above but Im still only getting the cell to change to red instead of the entire row.
Code:
      Cells.Select
    Selection.FormatConditions.Add Type:=xlTextString, String:="(OBSOLETE", _
        TextOperator:=xlBeginsWith
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
 
    
  '  With Selection.FormatConditions(1).Interior
    With Selection.EntireRow.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Range("C12").Select
 
End Sub
 
Upvote 0
Delete any old format conditions that no longer apply
- every time you run macro containing .FormatConditions.Add another condition is added and they may conflict with each other

try this

Code:
Sub NewRule()
    With Cells
        .FormatConditions.Add Type:=xlExpression, Formula1:="=COUNTIF(1:1,""OBSOLETE"")>0"
        .FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
        With .FormatConditions(1).Interior
            .PatternColorIndex = xlAutomatic
            .Color = 255
            .TintAndShade = 0
        End With
        .FormatConditions(1).StopIfTrue = False
    End With
End Sub

It should highlight the row if any cell value in that row = "obsolete"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,585
Messages
6,120,394
Members
448,957
Latest member
Hat4Life

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