Closed Thread
Results 1 to 8 of 8

vba to change time to 24 hour

  1. #1
    Registered User
    Join Date
    12-01-2015
    Location
    ballarat
    MS-Off Ver
    2013
    Posts
    85

    vba to change time to 24 hour

    Hello,
    Hoping someone may be able to help me please.From the site I go to I click on download everyday and it sends an excel file down to me.I then copy the required information from that as per sample sheet.Now what I would like to be able to do is convert that time to 24 hour time with a vba macro.
    The times usually start about 10am in the morning and go through til about 9pm at night.
    So while there is no am/pm on the sheet there would not be any say 10pm to confuse the issue.When I copy from the downloaded Excel sheet and paste I do not format the column that the time is pasted into as shown in sample.
    Attached Files Attached Files

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,015

    Re: vba to change time to 24 hour

    .
    How are you to determine if these times are AM or PM without some indicator already present ?

    If you were to convert the times as is, VBA would not understand which is which.

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: vba to change time to 24 hour

    If all the times are between 10am and 9pm, a formula like =TIMEVALUE(A1)+IF(FIND(":",A1)>2,0,0.5) should convert them into excel serial times. Formatting would add the AM or PM as needed.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  4. #4
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: vba to change time to 24 hour

    this would place the formated 24hr time in column f
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    12-01-2015
    Location
    ballarat
    MS-Off Ver
    2013
    Posts
    85

    Re: vba to change time to 24 hour

    Hello,
    Thank you both for prompt response to my query.
    @Logit The times run in order so if there was 10:30 it would be at start then 11:30 followed by 2:30,7:30.
    @mikerickson Thank you for such a sweet solution.
    I have enclosed sheet showing your answer as suggested which I have been able to convert to the time format I require.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    12-01-2015
    Location
    ballarat
    MS-Off Ver
    2013
    Posts
    85

    Re: vba to change time to 24 hour

    Hello RCM,
    I replied before I was notified re your response.Thank you very much.I now have two ideal solutions.
    Appreciate you taking the time to help.

  7. #7
    Forum Expert
    Join Date
    11-28-2012
    Location
    Guatemala
    MS-Off Ver
    Excel 2010
    Posts
    2,394

    Re: vba to change time to 24 hour

    Any time. You asked for a VBA solution.

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2405 (Windows 11 23H2 64-bit)
    Posts
    81,372

    Re: vba to change time to 24 hour

    This thread is closed as a duplicate. In future, if you are happy with either a formula or VBA solution, make this clear in your thread title. You are allowed one thread per issue here only - continue in the other thread, please: https://www.excelforum.com/excel-new...o-24-hour.html
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 1
    Last Post: 12-19-2017, 10:46 AM
  2. Replies: 5
    Last Post: 07-29-2016, 03:15 AM
  3. Replies: 0
    Last Post: 03-07-2014, 11:26 AM
  4. Replies: 8
    Last Post: 08-15-2012, 11:36 AM
  5. VBA to convert 12 hour to 24 hour time
    By Krrattner in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-29-2012, 06:59 PM
  6. Convert 12 hour to 24 hour time
    By RussellNonBrand in forum Excel General
    Replies: 5
    Last Post: 01-26-2011, 03:01 PM
  7. 24 hour time to change date
    By wlinton195 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-07-2008, 12:25 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