• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Strange problem with date format

Belleke

Well-Known Member
For some reason that I can't find out.
With this code the first 3 rows have the US date format, the rest is correct.
Code:
Sub Dotchie()
Dim Rng As Range, Dn As Range
Dim St As Date, oEnd As Date, n As Date
Dim p As Long
Dim c As Integer
p = 1
Set Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
St = Application.Min(Rng.Offset(, 1).Resize(, 2))
    oEnd = Application.Max(Rng.Offset(, 1).Resize(, 2))
      ReDim Ray(1 To oEnd - St + 2, 1 To 2)
            Ray(1, 1) = "Datum": Ray(1, 2) = "Bedden in gebruik"
For n = St To oEnd
        p = p + 1
    For Each Dn In Rng
        If n >= Dn.Offset(, 1) And n <= Dn.Offset(, 2) Then
            c = c + 1
        End If
    Next Dn
        Ray(p, 1) = Format(n, "dd/mm/yyyy"): Ray(p, 2) = c
        c = 0
Next n
    Range("D1").Resize(p, 2) = Ray
End Sub

Please advice
 
That's because dd/mm/yyyy for first three rows can also be valid dates in mm/dd/yyyy format.
10/10/2016
11/10/2016
12/10/2016
 
Depends on your set up.

Check your setting.

What is default date format used for your system (Region & Language)?
upload_2016-11-2_10-4-29.png

What is the default language set for Excel?

One solution is to format the cell as TEXT and not as date.
 
Back
Top