+ Reply to Thread
Results 1 to 12 of 12

Pull Month, Year, Time from String

  1. #1
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Pull Month, Year, Time from String

    Hello All,

    I have a sheet which captures the below date/time stamp. I need a function to pull the month and time in a 12 hour format and place this data into another column. I can code this via a cell (=MONTH(A2)), but need it to be written as a function in VB. I have been searching the forum, but am unable to locate the solution.

    Example Date/Time Stamp:
    9/19/2018 18:53

    Thanks,

    Lon

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,964

    Re: Pull Month, Year, Time from String

    I don't understand why you need a function to return the month when you can use MONTH() in formulas and VBA?

    Please Login or Register  to view this content.
    Ben Van Johnson

  3. #3
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Re: Pull Month, Year, Time from String

    Hello Ben,

    I need this to be coded in VB as a loop that breaks out the date and time and place this data into separate columns. Hope this makes sense.

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,964

    Re: Pull Month, Year, Time from String

    You'll have to mod for output cells:
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Re: Pull Month, Year, Time from String

    I am unable to get the above code to work. I put together the below code as an example, but am unable to get this to work correctly.

    Sub dts()
    Dim x As Long, LR As Long

    LR = Worksheets("iPad Tracker Raw Data").Cells(Rows.Count, "A").End(xlUp).Row

    With Sheets("iPad Tracker Raw Data").Range("a2:a" & LR)
    m = Month(Range("J2:J").Value)

    End With
    End Sub

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,362

    Re: Pull Month, Year, Time from String

    In which column are the Date/Timestamps and in which columns do you want the results displayed ?
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  7. #7
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Re: Pull Month, Year, Time from String

    Hello,

    Column "J" would be the month and column "I" would be the year.

    Thanks for the help.

    Lon

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,362

    Re: Pull Month, Year, Time from String

    Please Login or Register  to view this content.
    Last edited by bakerman2; 09-23-2018 at 10:02 PM. Reason: Fixed error.

  9. #9
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Re: Pull Month, Year, Time from String

    Thank-you,

    I am getting an error as follows: Object Required. It stepped into the code via debug, and it fails at this point:
    For Each cl In .Range("a2:a" & LR)

    Thanks for your help,

    Lon

  10. #10
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,180

    Re: Pull Month, Year, Time from String

    Try:
    Please Login or Register  to view this content.

  11. #11
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,964

    Re: Pull Month, Year, Time from String

    Please Login or Register  to view this content.
    Last edited by protonLeah; 09-23-2018 at 09:33 PM.

  12. #12
    Forum Contributor
    Join Date
    09-21-2014
    Location
    USA
    MS-Off Ver
    2013
    Posts
    263

    Re: Pull Month, Year, Time from String

    Works perfect! Thankyou!

    Lon

+ 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] Pull year out of cell string of information
    By TotallyLost in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-23-2018, 05:16 PM
  2. Pull dates from multiple columns that fall into the same month/year.
    By safrau in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-23-2014, 12:15 PM
  3. find time left in month.days unit between two dates(in YEAR.MONTH.DAY)
    By xcfeng95 in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 02-21-2014, 12:55 PM
  4. Replies: 3
    Last Post: 11-26-2013, 02:34 PM
  5. [SOLVED] Extract Text from String then Convert to a Date (Month/Year)
    By sgrey24 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-14-2013, 06:11 PM
  6. Replies: 5
    Last Post: 11-06-2012, 04:56 PM
  7. Date/Time Function in Excel (Day/Month/Year & time)
    By tortuga32 in forum Excel General
    Replies: 19
    Last Post: 12-14-2011, 02:00 AM

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