Highlight a cell if it falls between 2 values on the worksheet AND text in another cell is x

ffc2004

New Member
Joined
Apr 29, 2019
Messages
14
Hi all,

I have a worksheet set up with dates that an area is booked for, and a calendar set up on the same sheet. Currently I've got it highlighting the date on the calendar if the date is entered on the worksheet by conditional formatting if values are between cell x and cell y, but what I would like to do is only highlight the date if they fall between these ranges AND cell z contains specific text. eg if cell O11 contains "Heath" then it would highlight the dates from J11-K11 on the calendar. Can this be done?

https://ibb.co/mhMhF3j is how it currently looks, I've tried <code style="margin: 0px; padding: 1px 5px; border: 0px; font-variant-numeric: inherit; font-variant-east-asian: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; background-color: rgb(239, 240, 241); white-space: pre-wrap; color: rgb(36, 39, 41);">=IF($A$12=$O$11,AND(B11>=$J$11,B11<=$K$11))</code> but it only seems to work for the first row of dates.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
When entering a formula into CF you do not need to use IF

Is this what you want?
Code:
=AND($A$12=$O$11,B11>=$J$11,B11<=$K$11)
 
Upvote 0
Try this VBA code

Right click on the tab and select view code.
past the below code into the VBA editor

When you change A12 the code will run. If you put in a location in A12 that is not in the list then all the colors will be cleared and nothing will be highlighted.


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A12")) Is Nothing Then
Dim cell As Range
Dim mrng As Range
Dim loc As Range
Dim rcount As Long
Set mrng = Range("B11:H15")
Set loc = Range("A12")
rcount = Cells(11, "J").End(xlDown).Row
    mrng.Interior.Color = xlNone
    For Each cell In mrng
        For x = 11 To rcount
            If Cells(x, "O") = loc And cell >= Cells(x, "J") And cell <= Cells(x, "K") Then
                cell.Interior.Color = vbYellow
            End If
        
        Next x
    
    Next cell
End If
End Sub
 
Upvote 0
Try this VBA code

Right click on the tab and select view code.
past the below code into the VBA editor

When you change A12 the code will run. If you put in a location in A12 that is not in the list then all the colors will be cleared and nothing will be highlighted.


Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A12")) Is Nothing Then
Dim cell As Range
Dim mrng As Range
Dim loc As Range
Dim rcount As Long
Set mrng = Range("B11:H15")
Set loc = Range("A12")
rcount = Cells(11, "J").End(xlDown).Row
    mrng.Interior.Color = xlNone
    For Each cell In mrng
        For x = 11 To rcount
            If Cells(x, "O") = loc And cell >= Cells(x, "J") And cell <= Cells(x, "K") Then
                cell.Interior.Color = vbYellow
            End If
        
        Next x
    
    Next cell
End If
End Sub

This is great, thank you - the only amendment I would need is that I also change A11 to change the month?
 
Upvote 0
Change the first line to
Code:
If Not Intersect(Target, Range("A12")) Is Nothing Or Not Intersect(Target, Range("A11")) Is Nothing Then
 
Upvote 0
Another one - is there any way to make the range a series of text boxes instead of a range of cells?
 
Upvote 0
I do not use text boxes much but I would think it could be done.

What would be in the text boxes?
 
Upvote 0
I do not use text boxes much but I would think it could be done.

What would be in the text boxes?

The calendar range I have set up currently would be a set of grouped text boxes - the calendar is currently on the left half of the sheet and the table of data on the right. When I filter the data when needed it then hides the rows with calendar data, but I can't move the calendar above the table without messing up the column widths I need so was looking to create the calendar with text boxes linked to the cell reference on another sheet.

Sorry if that doesn't make much sense!
 
Upvote 0

Forum statistics

Threads
1,224,891
Messages
6,181,614
Members
453,057
Latest member
LE102024

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