0

I am trying to auto filter datasets pertaining to a set date array which are stored in the UK format - for ex: 11/04/2019 (April 11, 2019), 15/04/2019 (April 15, 2019). The macro is converting the UK date format to US format, however, it is filtering only those dates which are under 12 and is discarding those above 12. The code I used is shown below:

i = 0
For Each iCell In Control.Range(Cells(5, 3), Cells(99, 3))
    If iCell.Value <> "" Then
    'CONVERT DATE TO US FORMAT FOR VBA
        iDte = Format(iCell, "mm/dd/yyyy")
        i = i + 2
        ReDim Preserve DteAry(1 To i)
        DteAry(i - 1) = 2
        DteAry(i) = iDte
    End If
Next iCell

[Dates to be filtered][1]

1
  • I've found use of a function like this one to split up the day, month and year and put it all together can help when experiencing region based issues with date formats. Commented May 9, 2021 at 12:58

1 Answer 1

0

If you store true date values, not text, these carry no format, so:

    iDte = iCell
    i = i + 2
    ReDim Preserve DteAry(1 To i)
    DteAry(i - 1) = 2
    DteAry(i) = iDte
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for getting back. I tried the code you suggested, however, it is not able to filter anything and is returning empty values. The date values in the array are stored as true date values with the date format, and the raw data from which I am trying to filter out has them in custom format, such as 11/04/2019 07:00:00 etc., Any other advice pls?
True date values carry no format, thus no format is "stored" within the array. So, it is unclear what you are doing. For comparing date values, use DateDiff.
Is it possible for me to send a sample macro for your perusal?
Yes, add it to your question for everyone to study.
Thanks, I have included a link to the macro and a sample file as suggested.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.