Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
'/Claus @ MS PUBLIC
If Intersect(Target, Range("1:1")) Is Nothing Or _
Target.Count > 1 Then Exit Sub
Dim c As Range, rngC As Range
Dim LRow As Long, LCol As Long, i As Long, n As Long
Dim varData1 As Variant, varData2 As Variant, varOut() As Variant
Dim NumToFind As Date
NumToFind = Target
If NumToFind = 0 Then
Target.Offset(1).Resize(300, 2).ClearContents
Exit Sub
End If
With Sheets("Deputy Availability")
LRow = .Cells(.Rows.Count, 2).End(xlUp).Row
LCol = .Cells(2, .Columns.Count).End(xlToLeft).Column
Set c = .Range(.Cells(2, 3), .Cells(2, LCol)).Find(NumToFind, LookIn:=xlFormulas)
If Not c Is Nothing Then
varData1 = .Range(.Cells(34, c.Column), .Cells(LRow, c.Column))
varData2 = .Range(.Cells(34, 2), .Cells(LRow, 2))
Else
MsgBox "Value not found": Beep: Exit Sub
End If
n = 1
For i = LBound(varData1) To UBound(varData1)
If varData1(i, 1) <> "" Then
ReDim Preserve varOut(1 To 2, 1 To n)
varOut(1, n) = varData2(i, 1)
varOut(2, n) = varData1(i, 1)
n = n + 1
End If
Next
End With
Target.Offset(1).Resize(300, 2).ClearContents
Target.Offset(1).Resize(n - 1, 2).Value = Application.Transpose(varOut)
End Sub