Set Interior Color for Portions of Rows with Text Present

imtclimb

New Member
Joined
Nov 26, 2016
Messages
2
Hi - I am trying to set a different interior color for portions of any row that has text present in Column J. So far I have been able to set the interior color for that cell in Column J only. I need to figure out who to be able to also set the interior color for Column B through Column I when there is text present in Column J. Here is what I have so far. I am thinking that I need to use an ActiveCell.Offset, but it is not working for me. I am wondering if I don't have an "ActiveCell" b/c of what else is going on in my macro. Any help would be greatly appreciated!

Sub ChangInteriorFillColor()


Dim zrng As Range
Dim zrr As Range
Dim zsAdd As String
Dim zsStr As String


zsStr = "total"


With Worksheets("Rollover").Range("J1:J500")
Set zrng = .Find(zsStr)
If Not zrng Is Nothing Then
zsAdd = zrng.Address
Do
If zrr Is Nothing Then
Set zrr = zrng
Else
Set zrr = Application.Union(zrr, zrng)
End If
Set zrng = .FindNext(zrng)
Loop While Not zrng Is Nothing And zrng.Address <> zsAdd
End If
End With


If Not zrr Is Nothing Then
zrr.Interior.Color = RGB(192, 192, 192)



End If
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
19,343
Office Version
  1. 2021
Platform
  1. Windows
Try this:

Code:
Sub Test()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "J").End(xlUp).Row
    
    For i = 1 To Lastrow
        If Cells(i, "J").Value <> "" Then
            Range("B" & i & ":J" & i).Interior.ColorIndex = 4
        End If
    Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Sektor

Well-known Member
Joined
May 6, 2011
Messages
2,874
Office Version
  1. 365
Platform
  1. Windows
Would be more readable:
Code:
Range(Cells(i, "B"), Cells(i, "J").Interior.ColorIndex = 4
Or this way:
Code:
Cells(i, "B").Resize(, 9).Interior.ColorIndex = 4
 
Upvote 0

MARK858

MrExcel MVP
Joined
Nov 12, 2010
Messages
15,025
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
Another option if your cells in column J are text and not the result of formula

Code:
Sub ColTxt()
   With Columns("J:J").SpecialCells(xlCellTypeConstants, 23)
        .Interior.Color = RGB(192, 192, 192)
        .Offset(, -8).Interior.Color = RGB(192, 192, 192)
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,191,060
Messages
5,984,414
Members
439,885
Latest member
Akshay1

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
Top