Sub test()
Dim ddate As Date, rdata As Range, filt As Range, mmonth As String
Worksheets("sheet1").Activate
ddate = Range("B1").Value
mmonth = WorksheetFunction.Text(ddate, "mmm")
'MsgBox mmonth
Set rdata = Range("a3").CurrentRegion
'MsgBox rdata.Address
rdata.AutoFilter Field:=4, Criteria1:=">=" & ddate, Operator:=xlAnd, Criteria2:="<" & ddate + 1
Set filt = rdata.Offset(1, 0).Resize(rdata.Rows.Count - 1, rdata.Columns.Count).SpecialCells(xlCellTypeVisible)
filt.Copy
If Not SheetExists(mmonth) Then
Worksheets.Add after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = mmonth
End If
With ActiveSheet
.Range("a1").PasteSpecial
End With
Worksheets("sheet1").Activate
ActiveSheet.AutoFilterMode = False
Application.CutCopyMode = False
End Sub
Function SheetExists(SheetName As String) As Boolean
' returns TRUE if the sheet exists in the active workbook
SheetExists = False
On Error GoTo NoSuchSheet
If Len(Sheets(SheetName).Name) > 0 Then
SheetExists = True
Exit Function
End If
NoSuchSheet:
End Function
Bookmarks