KyleJackMorrison
Board Regular
- Joined
- Dec 3, 2013
- Messages
- 107
- Office Version
- 365
- 2021
- 2019
- Platform
- Windows
Hello,
I have a document (shared) which we use as a calendar and to keep track of people and where they are. It has all 365 day on it and with over 100 people.
I would like a vba to search the document and change the cell colour based on the value. For example: Red if someone is away on holiday. Green if they are on a course.
I use conditional formatting however as people copy and paste in the document, it copies the conditional formation stuff which now has rendered the document unworkable as it crashes due to too many conditional formatting rules.
I have also tried a simple code which colours the cells based on a value, however if someone types "holiday" or "HOLIDAY" it wont change the colour due to the code only searching for "Holiday" in ProperCase.
Is there a more efficient way of having a code where i don't have to put in every type of case search criteria which will slow down the sheet.
Many thanks in advance!
(Current code im using)
I have a document (shared) which we use as a calendar and to keep track of people and where they are. It has all 365 day on it and with over 100 people.
I would like a vba to search the document and change the cell colour based on the value. For example: Red if someone is away on holiday. Green if they are on a course.
I use conditional formatting however as people copy and paste in the document, it copies the conditional formation stuff which now has rendered the document unworkable as it crashes due to too many conditional formatting rules.
I have also tried a simple code which colours the cells based on a value, however if someone types "holiday" or "HOLIDAY" it wont change the colour due to the code only searching for "Holiday" in ProperCase.
Is there a more efficient way of having a code where i don't have to put in every type of case search criteria which will slow down the sheet.
Many thanks in advance!
(Current code im using)
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)Dim myRange As Range
Dim myCell As Range
Set myRange = Range("G5:NL104")
For Each myCell In myRange
If InStr(1, (myCell.Value), "Leave") > 0 Then
myCell.Interior.ColorIndex = 6
End If
For Each myCell In myRange
If InStr(1, (myCell.Value), "LEAVE") > 0 Then
myCell.Interior.ColorIndex = 6
End If
For Each myCell In myRange
If InStr(1, (myCell.Value), "leave") > 0 Then
myCell.Interior.ColorIndex = 6
End If
For Each myCell In myRange
If InStr(1, (myCell.Value), "Holiday") > 0 Then
myCell.Interior.ColorIndex = 6
End If
For Each myCell In myRange
If InStr(1, (myCell.Value), "HOLIDAY") > 0 Then
myCell.Interior.ColorIndex = 6
End If
For Each myCell In myRange
If InStr(1, (myCell.Value), "holiday") > 0 Then
myCell.Interior.ColorIndex = 6
End If
Next myCell
End Sub