Results 1 to 4 of 4

Thread: [RESOLVED] [Excel VBA]Filtering Data from Excel Sheet

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2007
    Posts
    139

    Resolved [RESOLVED] [Excel VBA]Filtering Data from Excel Sheet

    Hi,

    I have a excel data which is looking like the attachment image.

    I want to add one function into the userform which can let the user to select and filtering the date according the age. Referring to the attachment userfrom (Two options: 25 - 29 years old and 30 years old and above)

    Inside my data excel sheet, there are date of birth coloumn. Can anyone show me how should i write the command to filter according the age
    (P/S: The D.O.B Column was format as Date and i have attach the excel file as well)

    Thank you in advance
    Attached Images Attached Images   
    Attached Files Attached Files

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jul 2007
    Posts
    139

    Re: [Excel VBA]Filtering Data from Excel Sheet

    Any advice would be appreciated?

    i thought of using the formula =right(E3,4) to get the last four digit from the DOB. But the problem is the DOB column format is Date, even i use the formula =right(E3,4), I can't get the correct Year of Birth.

  3. #3
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,470

    Re: [Excel VBA]Filtering Data from Excel Sheet

    whe you deal with ages you need to be sure to know exactly when you want your age calculations to start. for schools in england for example ages are calculated from the start of the autumn term so thats September.

    her we will just assume january the first

    so the year of their birth from the year now will give you the age of the person

    thats year(now())- year(stored date)

    you can also use the datediff()

    it needs to know the dates and the units it is calculating in "y" is for years if i remember, but its in the help anyway...

    just checked for a column e row 4 the entry is 1/1/1984 the next column entry is =year(e4) returns 1984 ... job done

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jul 2007
    Posts
    139

    Re: [Excel VBA]Filtering Data from Excel Sheet

    Thank for your help. I've solve it. Below are the code that i use it for filtering year, month and day.

    Code:
     If TWOFIVEOB.Value = True Then _
                .AutoFilter Field:=13, Criteria1:=">1/1/1983", _
                 Operator:=xlAnd, Criteria2:="<12/31/1987"
                
                If THREEZEROOB.Value = True Then _
                .AutoFilter Field:=13, Criteria1:="<=12/31/1982"

Posting Permissions

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



Click Here to Expand Forum to Full Width