+ Reply to Thread
Results 1 to 10 of 10

Formatting Multiple number values in a cell into time values.

  1. #1
    Registered User
    Join Date
    02-26-2023
    Location
    australia
    MS-Off Ver
    Office 2021
    Posts
    4

    Formatting Multiple number values in a cell into time values.

    Hi,
    I'm copying multiple time values into a single cell using vba with a space as a separator, however it is resulting in a cell with a bunch of numbers and I am unable to format it back into time.
    Snipaste_2023-02-27_09-49-52.pngSnipaste_2023-02-27_09-49-52.png

    Is there anyway to convert into time format?

    This is the macro I'm using to copy the cells:
    where ws1.Cells(y,"E") contains the time values I want to copy

    For y = 2 To 3024

    If ws1.Cells(y, "A").Value = ws2.Cells(x, "A").Value Then
    If ws1.Cells(y, "E") = "6/02/2023" Then
    ws3.Cells(x, "B").Value = ws3.Cells(x, "B").Value & " " & ws1.Cells(y, "F")

    ElseIf ws1.Cells(y, "E") = "7/02/2023" Then
    ws3.Cells(x, "C").Value = ws3.Cells(x, "C").Value & " " & ws1.Cells(y, "F")
    ElseIf ws1.Cells(y, "E") = "8/02/2023" Then
    ws3.Cells(x, "D").Value = ws3.Cells(x, "D").Value & " " & ws1.Cells(y, "F")
    ElseIf ws1.Cells(y, "E") = "9/02/2023" Then
    ws3.Cells(x, "E").Value = ws3.Cells(x, "E").Value & " " & ws1.Cells(y, "F")
    ElseIf ws1.Cells(y, "E") = "10/02/2023" Then
    ws3.Cells(x, "F").Value = ws3.Cells(x, "F").Value & " " & ws1.Cells(y, "F")
    ElseIf ws1.Cells(y, "E") = "11/02/2023" Then
    ws3.Cells(x, "G").Value = ws3.Cells(x, "G").Value & " " & ws1.Cells(y, "F")
    ElseIf ws1.Cells(y, "E") = "12/02/2023" Then
    ws3.Cells(x, "H").Value = ws3.Cells(x, "H").Value & " " & ws1.Cells(y, "F")
    ElseIf ws1.Cells(y, "E") = "13/02/2023" Then
    ws3.Cells(x, "I").Value = ws3.Cells(x, "I").Value & " " & ws1.Cells(y, "F")
    ElseIf ws1.Cells(y, "E") = "14/02/2023" Then
    ws3.Cells(x, "J").Value = ws3.Cells(x, "J").Value & " " & ws1.Cells(y, "F")
    End If
    End If

    Next y

    Next x

    Thank your for your assistance.
    Attached Files Attached Files
    Last edited by sinneduo; 02-26-2023 at 07:58 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,154

    Re: Formatting Multiple number values in a cell into time values.

    This is the macro I'm using to copy the cells:
    If you concatenate values using ampersand ( & ), then you get Text as your output. In this case, you are concatenating raw numeric time values. You woud need to use Format with each of the time cell values. You will NEVER be able to format the worksheet cell in any way as it is Text.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,154

    Re: Formatting Multiple number values in a cell into time values.

    Note, with 2021, you could probably use FILTER and TEXTJOIN together with TEXT to get the output you require.


    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file and a mocked up solution.

  4. #4
    Registered User
    Join Date
    02-26-2023
    Location
    australia
    MS-Off Ver
    Office 2021
    Posts
    4

    Re: Formatting Multiple number values in a cell into time values.

    Thanks TMS, that makes sense.
    Just so i'm on the right page, am I formatting the cell before, after or both when copying the values:
    ws3.Cells(x, "B").Value = ws3.Cells(x, "B").Value & " " & ws1.Cells(y, "F")
    I also assume I would be using something like this to format the cell:
    Format(ws3.cells(x,"B", "Long Time")

  5. #5
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Formatting Multiple number values in a cell into time values.

    attach example excel file not a picture

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,154

    Re: Formatting Multiple number values in a cell into time values.

    Assuming ws1.Cells(y, "F") is the cell with the time, then:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-26-2023
    Location
    australia
    MS-Off Ver
    Office 2021
    Posts
    4

    Re: Formatting Multiple number values in a cell into time values.

    Apologies, I've attached file to main post

  8. #8
    Registered User
    Join Date
    02-26-2023
    Location
    australia
    MS-Off Ver
    Office 2021
    Posts
    4

    Re: Formatting Multiple number values in a cell into time values.

    Hi TMS,
    Just tried it and it works! thanks a lot!

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,154

    Re: Formatting Multiple number values in a cell into time values.

    I thought you said:

    Hi TMS,
    I just tried that and it converted all numbers into decimal format.


    Whatever … If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  10. #10
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Formatting Multiple number values in a cell into time values.

    Quote Originally Posted by sinneduo View Post
    Apologies, I've attached file to main post
    ........................
    err.png

+ 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. How to apply multiple formatting in same cell for concatenated values
    By axceron in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-15-2022, 04:10 PM
  2. Replies: 3
    Last Post: 10-11-2020, 10:00 PM
  3. [SOLVED] Conditional Formatting cell range containing Time Values formatted as [h]:mm;@
    By stewart@itsit.com.au in forum Excel General
    Replies: 8
    Last Post: 07-31-2019, 09:45 PM
  4. Replies: 7
    Last Post: 09-29-2016, 11:34 AM
  5. Replies: 2
    Last Post: 05-17-2016, 11:17 AM
  6. Replies: 16
    Last Post: 09-18-2014, 09:59 AM
  7. [SOLVED] Conditional formatting multiple number values but IGNORING text.
    By Dazmeister in forum Excel General
    Replies: 14
    Last Post: 09-06-2013, 09:02 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