筛选两个值的列

问题描述 投票:0回答:1

我想按完成日期和空白以及按状态过滤工作表。我想要的状态是“正在排队”和“已完成”。这应该会生成一张表格,显示输入日期完成的内容、队列中的内容以及空白,让我知道今天有一批未完成。

我制作了一个宏,将活动工作表作为电子邮件发送给团队。

工作电子邮件部分以及过滤器的代码。我尝试了自动筛选,但它按签入日期而不是完成日期进行筛选,并且它尝试在签入日期列中查找“在队列中”。

第一个工作表的名称是 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
excel vba autofilter
1个回答
0
投票

这对我有用:

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
© www.soinside.com 2019 - 2024. All rights reserved.