Private Sub Workbook_Open()
'nama of sheet
Worksheets("NSeries").Select
Dim stDate As Long: stDate = Date + 2
Dim stDate1 As Long: stDate1 = Date + 4
Dim count As Integer
Dim sh As Worksheet
Dim wbNew As Workbook
count = 0
'filter data yang sesuai kondisi Today + 3
Range("B6:B2000").AutoFilter 1, Criteria1:=">" & stDate, _
Operator:=xlAnd, Criteria2:="<" & stDate1
Range("A6:EW2000").Copy 'copy data yang sudah di filter
Workbooks.Add 'create new workbook
Set wbNew = ActiveWorkbook
[A4].PasteSpecial xlPasteAll 'paste data yang di copy ke new workbook
[A4].PasteSpecial xlPasteValues
wbNew.Sheets(1).Name = "Monitoring List CKD N-Series" ' setting untuk mengubah nama sheet di workbook baru
wbNew.SaveAs "D:\Users\galih\Desktop\Reminder Monitoring Lot " & Format(Now, "dd-mmm-yy") & ".xlsx"
wbNew.Close 'close new workbook
For Each cell In Range("B7:B1994") 'range cell
If cell.Value = Date + 3 Then
Cells(3, 2).Interior.ColorIndex = 3
Cells(3, 2).Font.ColorIndex = 1
Range("B3").Value = cell.Value 'menampilkan tanggal yang sesuai dengan tanggal hari ini +3
count = count + 1
Else
End If
Next
' kondisi sending email hanya 1 kali
If count > 0 Then
'SendReminderMail
ElseIf count = 0 Then
End If
Worksheets("FSeries").Select
Range("B6:B2000").AutoFilter 1, Criteria1:=">" & stDate, _
Operator:=xlAnd, Criteria2:="<" & stDate1
Range("A6:EW2000").Copy 'copy data yang sudah di filter
Workbooks.Add 'create new workbook
Set wbNew = ActiveWorkbook
[A4].PasteSpecial xlPasteAll 'paste data yang di copy ke new workbook
wbNew.Sheets(2).Name = "Monitoring List CKD F-Series"
wbNew.SaveAs "D:\Users\muhammad.galih\Desktop\Reminder Monitoring Lot " & Format(Now, "dd-mmm-yy") & ".xlsx"
wbNew.Close 'close new workbook
For Each cell In Range("B7:B1994") 'range cell
If cell.Value = Date + 3 Then
Cells(3, 2).Interior.ColorIndex = 3
Cells(3, 2).Font.ColorIndex = 1
Range("B3").Value = cell.Value
count = count + 1
Else
End If
Next
If count > 0 Then
SendReminderMail
ElseIf count = 0 Then
End If
End Sub