×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Problems with copying times

Problems with copying times

Problems with copying times

(OP)
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.

RE: Problems with copying times

Change the second line  to

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

m777182

RE: Problems with copying times

(OP)
It worked. Many thanks. I never knew .Text before as it is not even mentioned in my VBA book!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources