Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems with copying times

Status
Not open for further replies.

Grafton54

Computer
May 9, 2005
11
GB
I am trying to copy a cell containing a time to another using .value but this results in a decimal!

Try running this on your computer:

Cells(1, 1).Value = "18:00"
Cells(1, 2).Value = Cells(1, 1).Value

In the first cell, the value is 18:00, but the value in the second cell is 0.75! (=18/24 perhaps?)

Can anybody explain why this happens? Is there is a way to copy the time correctly?

I know that a copy-and-paste will get round this, but I do not want to it because it will transfer all the formatting from my source cell to my target cell.

I think the answer is something very simple and I apologise if I have asked a stupid question, but I tried looking for the answer on the internet but found nothing.

Many thanks.
 
Replies continue below

Recommended for you

Change the second line to

Cells(1, 2).Value = Cells(1, 1).Text

m777182
 
It worked. Many thanks. I never knew .Text before as it is not even mentioned in my VBA book!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top