我正在为这张信息编写一个宏程序。它应该按完成日期和空白进行过滤,并按状态进行过滤。我想要的状态是“正在排队”和“已完成”。这应该会生成一张表格,显示输入日期已完成的内容、队列中的内容以及空白,让我知道今天未完成批次。
我制作了一个宏,将当前活动工作表作为电子邮件发送给团队,不需要编辑。但是,由于某种原因,要过滤的宏无法按预期工作。我想将宏分配给“生成报告”按钮。请注意,我希望过滤“完成日期”,而不是“入住日期”。
如果您能帮忙,请告诉我。
谢谢! --> 链接到 Google 云端硬盘上的文件
-J
这是电子邮件部分的代码以及我当前的过滤器代码。我已经删除并重写了,所以这不是最好的。我尝试过自动过滤器,但不幸的是它一直按签入日期而不是完成日期进行过滤,并且它一直试图在签入日期列中查找“在队列中”。
第一张表的名称是MasterLog
Sub filter_multiple()
With Sheets("MasterLog").Range("C3")
.AutoFilter field:=1, Criteria1:=Range("C1").Value
.AutoFilter field:=1, Criteria1:=Range("I1").Value
End With
With Sheets("MasterLog").Range("E3")
.AutoFilter field:=1, Criteria1:=Range("P1").Value
.AutoFilter field:=1, Criteria1:=Range("Q1").Value
End With
End Sub
Sub EmailActiveSheet()
Dim OutApp As Object
Dim OutMail As Object
Dim TempFilePath As String
Dim TempFileName As String
Dim FileFullPath As String
Dim ws As Worksheet
Dim TempWB As Workbook
' Set the worksheet you want to send
Set ws = ThisWorkbook.Sheets("MasterLog") 'Replace "SheetName" with your sheet's name
' Create a temporary copy of the sheet as a new workbook
ws.Copy
Set TempWB = ActiveWorkbook
' Define the temporary directory
TempFilePath = Environ$("temp") & "\"
' Check if the temporary directory exists, and create it if not
If Len(Dir(TempFilePath, vbDirectory)) = 0 Then
MkDir TempFilePath
End If
TempFileName = "TempSheet"
FileFullPath = TempFilePath & TempFileName & ".xlsx"
' Save the temporary workbook
TempWB.SaveAs FileFullPath, FileFormat:=51 ' 51 represents the xlsx file format
TempWB.Close False
' Create a new Outlook instance
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0) ' 0 represents a mail item
' Compose the email
With OutMail
.To = "[email protected]" ' Replace with the recipient's email address
.Subject = "Email Macro Test" ' Replace with your email subject
.Body = "Hello, please find the attached sheet." ' Replace with your email body
' Attach the specific sheet
.Attachments.Add FileFullPath
' Uncomment the next line to display the email before sending (for testing)
.Display
' Uncomment the next line to send the email immediately
' .Send
End With
' Clean up
Set OutMail = Nothing
Set OutApp = Nothing
' Delete the temporary file
Kill FileFullPath
End Sub
这对我有用:
Sub Macro1()
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("MasterLog")
With ws.Range("A2:N" & ws.Cells(Rows.Count, "A").End(xlUp).Row)
.AutoFilter Field:=3, _
Criteria1:=Array("=", ws.Range("C1").Value), _
Operator:=xlFilterValues
.AutoFilter Field:=5, _
Criteria1:=Array(ws.Range("P1").Value, ws.Range("Q1").Value), _
Operator:=xlFilterValues
End With
End Sub