Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6595511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:56:57+00:00 2026-05-25T17:56:57+00:00

This is my first question here, so I hope everything is correct. I’ve hacked

  • 0

This is my first question here, so I hope everything is correct. I’ve hacked a bit of code to read from excel and output a CSV with speech marks for every cell, blank or not. The problem is with the dates where excel converts a YYYY-MM-DD date to MM-DD-YYYY when it writes it to the CSV. To get around this I’ve written the following if statement:

If IsDate(Cells(r, c)) Then

Unfortunately the program now interprets a cell with “2A” in it as a date as well (even though I’ve checked the format in excel is text), exporting this as “1899-12-30”. I’ve put in a very quick and dirty clause to filter this

If Selection.Cells(r, c) = "2A" Then

But I was wondering if there was a more elegant way, to convert date formats that are only in the YYYY-MM-DD or similar format. And why it thinks A2 is a date!? Full code is below:

For r = 1 To Selection.Rows.Count
    s = """"
    c = 1
    For c = 1 To Selection.Columns.Count
            If IsDate(Selection.Cells(r, c)) Then
                'ridiculous clause to get rid of A2 being treated as a date
                If Selection.Cells(r, c) = "2A" Then
                    s = s & Selection.Cells(r, c)
                Else
                    s = s & Format(Selection.Cells(r, c), "YYYY-MM-DD")
                End If
            Else
                s = s & Selection.Cells(r, c)
            End If
            If c = Selection.Columns.Count Then
                s = s & """" 'end of row
            Else
                s = s & """,""" 'mid row
            End If
    Next c
    a.writeline s
Next r
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:56:58+00:00Added an answer on May 25, 2026 at 5:56 pm

    The problem arises because 2A is interpreted as 2 AM:

    ?isdate("2A")
    True
    
    ?cdate("2A")
    02:00:00 
    

    Dealing with this depends on what types of values are in the column alongside the dates, you could check their length or check for the default date that’s used when a DateTime contains no date part;

    if format$(cdate("2A"), "YYYY-MM-DD") = "1899-12-30" then ..dodgy..
    

    or look at its pattern; if isdate(x) and x like "####-##-##"
    or you could convert the value to a date and check that it falls within an appropriate range.

    You could also reformat the column itself Selection.NumberFormat = "yyyy-mm-dd".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first question here so I hope I can articulate it well
This is my first time here so I hope I post this question at
This is my first question here and I hope it is simple enough to
This is my first question here, so I hope that I am providing enough
this my first question on here. I hope someone can help. It is to
Since this is my first question here on stackoverflow I hope my question is
This is my first question here on stackoverflow, so I hope that I am
this is my first time asking a question here so I hope I am
this is my first question here so I hope I'm doing this right. I
this is my first question here. I hope dont make any mistake, be good

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.