extract time from excel to vb

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • newUser1234
    New Member
    • Jul 2007
    • 5

    extract time from excel to vb

    I've been trying to extract time from excel sheet cell to a vb text box, instead of giving me the time it gives me a double type number like "0.4375", in the excel file that cell has the value 10:30 AM.
    the code I'm using to extract it is as follows:

    Code:
    TextBox.Text = xlSheet.Cells(rowNum, 13).Value
    This code will extract all other types of values from the excel sheet cells i have except time, I don't know why. Any help would be greatly appreciated.
  • newUser1234
    New Member
    • Jul 2007
    • 5

    #2
    For anyone who is also looking up the same thing i found the solution, apparently vb stores time in double format, but it can be re-converted to time format using the following code:

    Code:
    myText.Text = .WorksheetFunction.Text(xlSheet.Cells(rowNum, 16).Value, "HH:MM:SS")

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Thanks for that.

      You were too quick for us, but it's always nice to get the answers in here, so anyone searching in future can find them.

      By the way, my guess is you could just take the double value that you obtained originally, and use Format() function to convert it to whatever date format you like.

      Comment

      Working...