Highlight specific text in cell

lockarde

Board Regular
Joined
Oct 23, 2016
Messages
77
Hello again all,
I have a macro that builds a calendar and searches sheets for details, placing them within the calendar if dates match. Each calendar day is only one cell, and so if more than one detail needs to go into the calendar day, I have it combine the details, separated by chr(10). I'm trying to get it so it turns any details red if they don't have a corresponding "completion date" but I can't figure out how to have it search through the one cell on the calendar for that detail and highlight only that specific one. It's easy when there is only one detail on that day - I have a nested if statement that checks if only one detail is there, and just changes the range text to red, but I can't get it to go through the string if more than one detail is in the calendar. The code I have is below:
VBA Code:
Do
              
            duedate = .Cells(jobfind.Row, c.Column).Value
            francode = .Cells(jobfind.Row, fc.Column).Value
            crtstyle = .Cells(jobfind.Row, cs.Column).Value
            'details are below
            jobdet = francode & " - " & crtstyle
           'next is a holder in case there is more than one detail to go into the calendar day, as jobdet gets overwritten later
            jobdethold = jobdet
            duemos = Month(duedate)
            dueyr = Year(duedate)
            dueday = day(duedate)
            Set cj = .Cells.Find("Comp Date")
            'grabs completion date below
            compdate = .Cells(jobfind.Row, cj.Column).Value
            If duemos = i And dueyr = yr Then
                Set duerng = Sheets("Calendar").Cells.Find(dueday, lookat:=xlWhole)
                Set duerng = duerng.Offset(1, 0)
                If Not duerng.Value2 = "" Then
                    
                    duerng.Value2 = duerng.Value2 & Chr(10) & Chr(10) & jobdet
                    If compdate = "" Then
                        
                      'This is where the text search would go. 
                      'I've found code that formats a range, and code that finds a character in a string, 
                      'but I can't find anything that searches out words within a string
                      'So ideally, code would search for jobdethold within jobdet, and highlight jobdethold red
                    Else

                    End If

                Else
                duerng.Value2 = jobdet
                    If compdate = "" Then
                       duerng.Font.Color = vbRed
                    End If
                End If
                Set jobfind = Sheets(x).Range("A1:A250").Find("Item 1", lookat:=xlWhole, after:=Range(jobfind.Address))
            Else
                
            End If
            next_jf_Address = jobfind.Address
        Loop While jobfind.Address <> first_jf_Address
    End With
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,214,827
Messages
6,121,824
Members
449,050
Latest member
Bradel

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