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:
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