VBA, Highlight If Text AND Dated After Specific Year

NEW_2VBA

Board Regular
Joined
Dec 15, 2015
Messages
106
Hello!
I used the following code to highlight an entire row if column F contained specific text, but I'm now struggling with how to also specify that it must be dated after 1/1/2013. So I'm looking to include those two conditions without using conditional formatting. :unsure:

Any feedback is greatly appreciated. Thank YOU!!! ?

Dim Cell As Range, Addr As String
With Range("F1", Cells(Rows.Count, "F").End(xlUp))
Set Cell = .Find("*Unit Costs*", , xlValues, , , , False, , False)
If Not Cell Is Nothing Then
Addr = Cell.Address
Do
Cell.EntireRow.Interior.Color = RGB(230, 184, 183)
Set Cell = .FindNext(Cell)
Loop While Not Cell Is Nothing And Cell.Address <> Addr
End If
 
I can't say thank you enough for your help! It worked! ? ?

I noticed however that the spreadsheet must contain both text strings. That how I got it to work.
The spreadsheet will either have: 1) Both text strings
2) One or the other
3) Neither
You are welcome. Here's a slight revision that addresses the run time error you cited. Replaces the previous code.
VBA Code:
Sub test()
Dim Cell As Range, Addr As String, Strs(1 To 2), Dts(1 To 2)
Strs(1) = "*Unit Costs*": Strs(2) = "*MILESTONE*"
Dts(1) = #1/1/2013#: Dts(2) = #1/1/2012#
For i = 1 To 2
    With Range("F1", Cells(Rows.Count, "F").End(xlUp))
        Set Cell = .Find(Strs(i), , xlValues, , , , False, , False)
        If Not Cell Is Nothing Then
            Addr = Cell.Address
        Else
            GoTo Nx
        End If
        Do
        If Cell.Offset(0, 3).Value > Dts(i) Then
            Cell.EntireRow.Interior.Color = RGB(230, 184, 183)
        End If
            Set Cell = .FindNext(Cell)
            If Cell Is Nothing Then Exit Do
            If Cell.Address = Addr Then Exit Do
        Loop
    End With
Nx: Next i
End Sub
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Forum statistics

Threads
1,215,026
Messages
6,122,738
Members
449,094
Latest member
dsharae57

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