Sub CheckCells()
' Defines variables
Dim Cell As Range, cRange As Range
Dim LastRow As Long
Dim Days5 As String, Days4 As String, Days3 As String, Days2 As String, Days1 As String
' Defines LastRow as the last row of data based on column K
LastRow = ActiveSheet.Cells(Rows.Count, "K").End(xlUp).Row
' Sets the check range as K1 to the last row of K
Set cRange = Range("K1:K" & LastRow)
' Defines the default states for all 5 message boxes
Days5 = "Totes expiring in 5 days: "
Days4 = "Totes expiring in 4 days: "
Days3 = "Totes expiring in 3 days: "
Days2 = "Totes expiring in 2 days: "
Days1 = "Totes expiring in 1 day: "
' For each cell in the check range
For Each Cell In cRange
' Select a case based on the cell value
Select Case Cell.Value
' Cell value of 5
Case 5
' If no totes have been added to the message box list yet then...
If Len(Days5) = 26 Then
' Add the tote number from column H to the message box list
Days5 = Days5 & Range("H" & Cell.Row).Value
' Else if there are already totes in the message box list then...
Else
' Add a comma and the tote number from column H to the message box list
Days5 = Days5 & ", " & Range("H" & Cell.Row).Value
End If
' Cell value of 4
Case 4
' If no totes have been added to the message box list yet then...
If Len(Days4) = 26 Then
' Add the tote number from column H to the message box list
Days4 = Days4 & Range("H" & Cell.Row).Value
' Else if there are already totes in the message box list then...
Else
' Add a comma and the tote number from column H to the message box list
Days4 = Days4 & ", " & Range("H" & Cell.Row).Value
End If
' Cell value of 3
Case 3
' If no totes have been added to the message box list yet then...
If Len(Days3) = 26 Then
' Add the tote number from column H to the message box list
Days3 = Days3 & Range("H" & Cell.Row).Value
' Else if there are already totes in the message box list then...
Else
' Add a comma and the tote number from column H to the message box list
Days3 = Days3 & ", " & Range("H" & Cell.Row).Value
End If
' Cell value of 2
Case 2
' If no totes have been added to the message box list yet then...
If Len(Days2) = 26 Then
' Add the tote number from column H to the message box list
Days2 = Days2 & Range("H" & Cell.Row).Value
' Else if there are already totes in the message box list then...
Else
' Add a comma and the tote number from column H to the message box list
Days2 = Days2 & ", " & Range("H" & Cell.Row).Value
End If
' Cell value of 1
Case 1
' If no totes have been added to the message box list yet then...
If Len(Days1) = 25 Then
' Add the tote number from column H to the message box list
Days1 = Days1 & Range("H" & Cell.Row).Value
' Else if there are already totes in the message box list then...
Else
' Add a comma and the tote number from column H to the message box list
Days1 = Days1 & ", " & Range("H" & Cell.Row).Value
End If
End Select
' Check next cell in check range
Next Cell
' If no totes have been added to the Days5 message box list then...
If Len(Days5) = 26 Then
' Display a Days5 message reporting "None"
MsgBox Days5 & "None", vbOKOnly, "5 Days"
' Else if totes have been added then...
Else
' Display the full Days5 message
MsgBox Days5, vbOKOnly, "5 Days"
End If
' If no totes have been added to the Days4 message box list then...
If Len(Days4) = 26 Then
' Display a Days4 message reporting "None"
MsgBox Days4 & "None", vbOKOnly, "4 Days"
' Else if totes have been added then...
Else
' Display the full Days4 message
MsgBox Days4, vbOKOnly, "4 Days"
End If
' If no totes have been added to the Days3 message box list then...
If Len(Days3) = 26 Then
' Display a Days3 message reporting "None"
MsgBox Days3 & "None", vbOKOnly, "3 Days"
' Else if totes have been added then...
Else
' Display the full Days3 message
MsgBox Days3, vbOKOnly, "3 Days"
End If
' If no totes have been added to the Days2 message box list then...
If Len(Days2) = 26 Then
' Display a Days2 message reporting "None"
MsgBox Days2 & "None", vbOKOnly, "2 Days"
' Else if totes have been added then...
Else
' Display the full Days2 message
MsgBox Days2, vbOKOnly, "2 Days"
End If
' If no totes have been added to the Days1 message box list then...
If Len(Days1) = 25 Then
' Display a Days1 message reporting "None"
MsgBox Days1 & "None", vbOKOnly, "1 Day"
' Else if totes have been added then...
Else
' Display the full Days1 message
MsgBox Days1, vbOKOnly, "1 Day"
End If
End Sub