+ Reply to Thread
Results 1 to 3 of 3

help with dates format and vba code

  1. #1
    Forum Contributor
    Join Date
    03-12-2018
    Location
    London, England
    MS-Off Ver
    2016
    Posts
    118

    help with dates format and vba code

    Hello everyone. I need some help!
    An online platform I use exports .csv files where a column is a date. For some random reason, but I guess because I am located in London and the files are generated in US (so with mm-dd format) some of the dates are recognized as such, whilst others are considered as text. You can see what I mean at row 242 of the file I am attaching.


    As I need all dates to be in the number format (44227 for example), I created the following code which splits the column A into day month and year, recombine and get the number in column G.


    Please Login or Register  to view this content.

    It works just fine.

    The problem I have is that it only works if I add the module directly in the csv file and run the macro there, whilst what I want is to start the macro from another file, pick the csv file and let it run the macro. If I do so, the format of the dates remain incorrect, ending up with #value error in the column G.

    This is the code I created:

    Please Login or Register  to view this content.

    I don't know if there is something I can do in the vba itself or it's a setting in the file with the macro perhaps?

    Can anyone help me?

    Thank you!
    Attached Files Attached Files

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: help with dates format and vba code

    You could do the conversion manually by following these steps:

    1 Select the column with the dates.

    2 Goto Data>Text to columns...

    3 Choose Delimited, click Next, click Next.

    4 On the 3rd step choose MDY from the Date dropdown in the Column data format section.

    P.S. You could do something similar to this if you imported the data from CSV file into Excel rather than opening the file directly.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: help with dates format and vba code

    Quote Originally Posted by thoandros View Post
    ... something I can do in the vba itself ...
    You took on this matter from the most tedious and time-consuming side - use Nori's advice.
    In Excel, you have ready-made text import mechanisms, which can additionally be turned into a macro, e.g.:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Convert Dates from Apr 11, 2018 format to numeric format MM/DD/YYYY
    By worswick25 in forum Excel General
    Replies: 16
    Last Post: 04-17-2018, 06:38 AM
  2. Replies: 3
    Last Post: 02-27-2017, 04:38 PM
  3. [SOLVED] VBA code pull data from SQL db - need output dates in proper date format
    By seatejo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-15-2014, 02:28 AM
  4. Convert Dates in 2011:08:17 format into Dates in Excel
    By JessRI in forum Excel - New Users/Basics
    Replies: 12
    Last Post: 09-11-2012, 09:55 AM
  5. Replies: 1
    Last Post: 04-26-2010, 08:14 AM
  6. Conditional Format Dates in a Calender when Matches dates in a list
    By Lungfish in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-14-2009, 06:23 AM
  7. [SOLVED] [SOLVED] the dates on cell format make different dates.
    By date formats morph the dates/chang case in forum Excel - New Users/Basics
    Replies: 7
    Last Post: 04-17-2005, 10:07 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1