+ Reply to Thread
Results 1 to 3 of 3

Text to Columns VBA date format error

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-20-2012
    Location
    Walsall,England
    MS-Off Ver
    Excel 2007
    Posts
    125

    Text to Columns VBA date format error

    Hi all,

    I'm writing a VBA procedure which involves using text to columns on a data set to make the data the right format (all the data is formatted as text initially). For each column I am using the 'General' data type which is selected in step 3 of the text to columns wizard.

    The issue I am having is with columns containing dates. When I run the vba procedure some of the dates will get formatted to dates (aligned right in their cells) but others will be left as text format (aligned left in their cells). This only happens with the vba procedure though - if done manually using text to columns they all convert correctly.

    Please see the dummy file I have attached as illustration. The procedure Macro 1 is just a recording of me performing the text to columns function. When done manually the data converts correctly, when the procedure is run the data does not convert correctly.

    By the way I am aware that I can change the data type in the array segment of the code to tell text to columns to format as date. However with my data set the columns can be in varying order and identifying which columns are meant to be dates is potentially a lot more coding.

    Thanks.
    Attached Files Attached Files

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,056

    Re: Text to Columns VBA date format error

    If you don't use
    FieldInfo:=Array(1, xlDMYFormat)
    you're out of luck because VBA will always default to US formats in the absence of any more specific information.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    08-20-2012
    Location
    Walsall,England
    MS-Off Ver
    Excel 2007
    Posts
    125

    Re: Text to Columns VBA date format error

    Darn. Thanks for the info.

+ 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] help on vba code to change the error date format as standard format mm/dd/yyyy
    By johnodys in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-13-2013, 01:10 AM
  2. [SOLVED] Text To Columns Date Format Error
    By Simon.Ward in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-17-2013, 03:59 AM
  3. [SOLVED] Use VBA to run "text to columns' Loop on first row to convert from text to date format
    By csmiley in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-03-2013, 02:06 PM
  4. [SOLVED] Unable to Format Date after using Text to Columns
    By tropsog in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-31-2013, 11:22 AM
  5. text to columns date error when using Macro
    By AntDingle in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-02-2009, 11:01 PM

Tags for this Thread

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