Consulting

Results 1 to 2 of 2

Thread: Double filter in VBA code

  1. #1
    VBAX Newbie
    Joined
    Apr 2015
    Posts
    3
    Location

    Double filter in VBA code

    Hi all,

    would you be able to advise how to apply two conditions in filter please?

    The thing is, that I need to filter only dates befor actual month and year in the same time. For example, today is 21.05.2015 so I need only entries related at latest to 31.4.2015. It's not able for me to change format to date and do easy function with dates, because this is output from internal system and format couldn't be change.

    Sub FilterMonths()


    Set original009 = Sheets("Original Input")


    Dim datum As Date
    Dim z As Integer


    datum = Date


    actualMonth = DatePart("m", datum)
    actualYear = DatePart("y", datum)

    z = 14


    original009.Range("J13") = "Month2"
    original009.Range("K13") = "Year2"


    Do While (original009.Cells(z, 9) <> "")


    original009.Cells(z, 10) = Mid(original009.Cells(z, 9), 4, 2)
    original009.Cells(z, 11) = Mid(original009.Cells(z, 9), 7, 4)


    z = z + 1


    Loop

    original009.Range("C13:K10000").AutoFilter Field:=8, Criteria1:="<>" & actualMonth, Field:=9, Criteria2:="<>" & actualYear


    End Sub


    And the input looks like this:


    Thank you a lot!

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    This will convert them to Dates.
    Option Explicit
    
    Sub ConvertToDate()
    Dim Cel As Range
    Dim DateRange As Range
    
      Set DateRange = Intersect(Range("C:C"), UsedRange) 'Edit Range Column to suit
      
      For Each Cel In DateRange
        Cel = CDate(Cel)
      Next
    End Sub
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •