Option Explicit
Sub test()
Dim myDate As Date, x As Double, temp
Dim Avbl As Long, Bkd As Long, DBkd As Long
Dim rng As Range, a, w, flg As Boolean
Dim i As Long, ii As Long, iii As Long
With Sheets("Check Availability")
myDate = .Range("D3").Value
Set rng = .Range("B5", .Range("B" & Rows.Count).End(xlUp)).Resize(, 27)
Avbl = .Range("J3").Interior.Color
Bkd = .Range("M3").Interior.Color
DBkd = .Range("Q3").Interior.Color
End With
With rng
With .Offset(1, 2).Resize(.Rows.Count - 1, .Columns.Count - 2)
.Interior.Color = Avbl
.ClearComments
End With
End With
If myDate = 0 Then GoTo Exit_Sub
a = Sheets("View ; Make Reservation").Range("B3").CurrentRegion.Value
With CreateObject("Scripting.Dictionary")
.CompareMode = 1
For i = 1 To UBound(a, 1)
If a(i, 1) = "" Then Exit For
If a(i, 1) = myDate Then
If Not .exists(a(i, 2)) Then
ReDim w(1 To 3, 1 To 1)
Else
w = .Item(a(i, 2))
ReDim Preserve w(1 To 3, 1 To UBound(w, 2) + 1)
End If
w(1, UBound(w, 2)) = Round(a(i, 3), 6)
w(2, UBound(w, 2)) = Round(a(i, 4), 6)
w(3, UBound(w, 2)) = a(i, 5)
.Item(a(i, 2)) = w
End If
Next
If .Count = 0 Then GoTo Exit_Sub
Application.ScreenUpdating = False
For i = 2 To rng.Rows.Count
If .exists(rng.Cells(i, 1).Value) Then
w = .Item(rng.Cells(i, 1).Value)
For ii = 1 To UBound(w, 2)
For iii = 3 To rng.Columns.Count
x = Round(rng.Cells(1, iii).Value, 6)
If x = w(1, ii) Then
flg = True
ElseIf x = w(2, ii) Then
Exit For
End If
If flg Then
If rng.Cells(i, iii).Interior.Color = Avbl Then
With rng.Cells(i, iii)
.Interior.Color = Bkd
.ClearComments
.AddComment w(3, ii)
.Comment.Shape.TextFrame.AutoSize = True
End With
Else
With rng.Cells(i, iii)
.Interior.Color = DBkd
temp = .Comment.Text
.Comment.Delete
.AddComment temp & vbLf & w(3, ii)
.Comment.Shape.TextFrame.AutoSize = True
End With
End If
End If
Next
flg = False
Next
End If
Next
End With
Exit_Sub:
Application.ScreenUpdating = True
Set rng = Nothing
End Sub
Bookmarks