zyterence
1/8/2017 - 8:29 AM

shenmegui.vba

Sub filter()
    '计算行数
    Dim sh As Worksheet
    Dim rn As Range
    Dim count As Integer
    
    Set sh = ThisWorkbook.Sheets(1)
    Set rn = sh.UsedRange
    count = rn.Rows.count
    
    '筛选数据
    Dim i As Integer
    Dim result As String
    result = ""

    For i = 1 To count
        If IsDate(Cells(i, 2)) Then
            Dim d As Date
            Dim n As Integer
            d = Cells(i, 2)
            n = DateDiff("d", Date, d)
                
            If n <= 5 Then
                result = result & Cells(i, 1) & vbTab & Cells(i, 2) & vbTab & Cells(i, 3) & vbCrLf
            End If
        End If
    Next i
        
    Dim title As String
    title = "5天内上映"
        
    MsgBox result, , title
End Sub