Auto coloring in the same row

HELIWTIS

New Member
Joined
Jul 26, 2022
Messages
4
Office Version
  1. 2019
Platform
  1. Windows
Hi,

I want your help.
I try to make a VBA macro that it will be searching TRD from column B and auto coloring in the same row on column A the corresponding number.


1658899218609.png
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
VBA Code:
Sub ColorIt()
    Dim LstRw As Long
    Dim arr As Variant, rPw As Long
    Dim rw As Long, cL As Long
    
    LstRw = Sheet1.Cells(Rows.Count, "B").End(xlUp).Row
    arr = Sheet1.Range("A1:B" & LstRw)
    rPw = 2
    For rw = 2 To UBound(arr)
        If arr(rw, 2) = "TRD" Then
            For cL = 1 To UBound(arr, 2)
                Cells(rw, 1).Interior.Color = vbYellow
            Next
            rPw = rPw + 1
        End If
    Next

End Sub
 
Upvote 0
Hi,
Please try this
VBA Code:
Sub ColorA()

    Columns("A:A").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$B1=""TRD"""
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 65535
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,778
Messages
6,174,482
Members
452,566
Latest member
Bonnie_bb

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