printing time literally

  • Thread starter Thread starter Bart van den Burg
  • Start date Start date
B

Bart van den Burg

Hi

I'm printing data from an excel sheet to a text file, and some of
these cells contain Time's. However, printing the cell results in a number
between 0 and 1 rather than the exact string, eg "12:30" or "4:00". How can
I print it like that anyway?

Thanks
Bart
 
Hi Bart;

You could try converting the values in the time based
cells to strings. Then when you print them to a text file
they will not show up as numbers.

Thanks,

Greg
 
Bart,

This will convert the value of the time to a string, held in the variable.
I then had to format the cell as text and then set the cell's value to the
string. After printing I formatted back to original format and reset the
value again - otherwise it didn't take.

Sub test()
Dim date_str As String
Dim cell_format As String

With Worksheets("Sheet1").Range("A1")
cell_format = .NumberFormat
date_str = CStr(Hour(.Value) & ":" & Minute(.Value))
.NumberFormat = "@"
.Value = date_str
'print to text file here
.NumberFormat = cell_format
.Value = date_str
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top