my VBA skills aren't the best, if someone could help with the following that would be great.
I have a number of sheets in a workbook that has a date record in the cell range E11:E37.
I'm trying to create a reporting function whereby the user completes a date picker userform, Excel runs a search on the above range in all worksheets in this workbook for a date that falls between the DTPicker1/2 results.
For sheets that return a match, copy all those sheets to a new workbook with name ("Name & current Date".xlsx).
Update: I tried reversing the > and <, no change, think i wrapped in Cdate for the DTPicker Values no results, did both, no results....
Update: code now working but doesnt return a value true where dates in range = 01/06/18 - 14/06/18 where DTP1 = 07/06/18 and DTP2 = 16/06/18. But does return true where DTP1 = 04/06/18 and DTP2 = 08/06/18.
Private Sub CommandButton1_Click()
Dim s As Worksheet, wb As Workbook
For Each s In Worksheets
If CBool(Application.CountIfs(s.Range("E11:E37"), ">" &
CDate(DTPicker1.Value), _
s.Range("E11:E37"), "<" &
CDate(DTPicker2.Value))) Then
If wb Is Nothing Then
s.Copy
Set wb = ActiveWorkbook
Else
s.Copy after:=wb.Worksheets(wb.Worksheets.Count)
End If
End If
Next s
If wb Is Nothing Then
MsgBox ("No Records Found")
Else
wb.SaveAs Filename:="Technicians - Batch Record Report" & Format(Date,
"ddmmyyyy"), _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
End If
End Sub