Consulting

Results 1 to 5 of 5

Thread: One Cell with different Time and Strings

  1. #1
    VBAX Regular
    Joined
    Mar 2016
    Posts
    12
    Location

    One Cell with different Time and Strings

    Hi everyone,

    Im writing a code were I have to read out cells from a sheet and they will be transfered to one cell. The thing is that the content in this cell should be:

    Sign in: (time) Sign out: (time)

    I want to keep it simple. I have allready written a code but it is really long. Is there a simple possibility to transfer text and time into one cell? Because if i just transfer it like a string the cell looks like:

    Sign in: 0.1684654 Sign out: 0.184654 (i know why but maybe there is a function or easy way to display the digits as normal time)

    It should look like:

    Sign in: 12:30 Sign out: 13:00

    I can also put the strings and times in different cells but then my question would be if can I can format a cell out of vba, because in the excel sheet the format of the cells is general.

    Thanks a lot

  2. #2

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,730
    Location
    Simple way


    Sub test()
        Dim s1 As String, s2 As String
        Dim v As Variant
        
        s1 = "Sign in: 0.1684654 Sign out: 0.984654"
        
        v = Split(s1, " ")
    
        s2 = "Sign in: " & Format(v(2), "[h]h:mm") & " Sign out: " & Format(v(5), "[h]h:mm")
    
        MsgBox s2
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Regular
    Joined
    Mar 2016
    Posts
    12
    Location
    Amazing. Thank you

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,730
    Location
    Be aware that it does make assumptions that the input string is consistently formatted
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •