+ Reply to Thread
Results 1 to 11 of 11

VBA to split date and time

  1. #1
    Forum Contributor
    Join Date
    11-07-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    126

    Angry VBA to split date and time

    Hi All,

    I have a spreadsheet where one cell has the date and time i.e 23/11/2014 13:00:00,

    I set up a VBA to split this (using text to columns) which worked the first time when recording the initial macro splitting the information into two cells one with the date and one with time time, however when this is run from the developer tab for further instances it now splits the cell into 3 columns (date, time and AM or PM).

    I do not need the am or pm column can anybody help?

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA to split date and time

    Use Excel's text to columns function. On the final stage of the process, you need to choose date for both columns and then format column A as date

  3. #3
    Forum Contributor
    Join Date
    11-07-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    126

    Re: VBA to split date and time

    Hi,

    thanks for the quick reply,

    I have just tried the above when I do this the first time recording the VBA it works fine and just splits into two columns, however when I try this again with the VBA I have recorded it splits the cell into 3 columns overwriting some other data in the 3rd cell?

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA to split date and time

    If the format are different in each line, yes it can happen. The only way to resolve is to see what you data look like. Please attach a sample.

  5. #5
    Registered User
    Join Date
    10-11-2011
    Location
    FB Republic
    MS-Off Ver
    2016
    Posts
    36

    Re: VBA to split date and time

    hi.

    assuming A1 houses the date, try this:

    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA to split date and time

    Quote Originally Posted by mancubus View Post
    hi.

    assuming A1 houses the date, try this:

    Please Login or Register  to view this content.
    Good, but you need to incorporate it on a loop as the OP has lots of rows.

  7. #7
    Forum Contributor
    Join Date
    11-07-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    126

    Re: VBA to split date and time

    Hi,

    thanks for this the above VBA code worked, how would I put this on a loop to include any row along the column (apologies for all the questions I am fairly new to VBA)

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA to split date and time

    It is code mancubus' code

    Assuming you have a header in row 1

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    11-07-2014
    Location
    UK
    MS-Off Ver
    2010
    Posts
    126

    Re: VBA to split date and time

    fantastic thank you both for your help it is much appreciated

  10. #10
    Registered User
    Join Date
    10-11-2011
    Location
    FB Republic
    MS-Off Ver
    2016
    Posts
    36

    Re: VBA to split date and time

    you are welcome.

    reading "one cell" in the first sentence, i assumed the OP needed a pointer.

    cheers.

  11. #11
    Registered User
    Join Date
    11-08-2014
    Location
    Malaysia
    MS-Off Ver
    2010
    Posts
    84

    Re: VBA to split date and time

    Hello,
    I have opened a new thread but I found something useful here for my case. But mine is a bit different. Could you please help me to solve my issue as well.
    This is my thread link.

+ 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] split day from date time
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-16-2014, 03:20 PM
  2. [SOLVED] Split Date and Time Cell
    By Beamers in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-17-2013, 03:22 PM
  3. Split Date and Time
    By aftabn10 in forum Excel General
    Replies: 3
    Last Post: 09-09-2008, 04:59 AM
  4. Split date and time automatically
    By Endorphin in forum Excel - New Users/Basics
    Replies: 11
    Last Post: 10-27-2006, 05:22 PM
  5. [SOLVED] Split date and time
    By Warsteiner in forum Excel General
    Replies: 2
    Last Post: 12-08-2005, 06:15 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