+ Reply to Thread
Results 1 to 4 of 4

Enter hours.minute in cell via VBA code

  1. #1
    Registered User
    Join Date
    07-15-2011
    Location
    Italy
    MS-Off Ver
    Excel 2003
    Posts
    2

    Enter hours.minute in cell via VBA code

    Hi all

    I want to insert a particular data into a cell via VBA code. This is my code:

    Cells(ActiveCell.Row, "D").NumberFormat = "[h].mm.ss"
    Cells(ActiveCell.Row, "D") = "8.3" '8 hours and 03 minutes

    Why after executing this code the cell contains 199.12.00 and not 8.03.00?
    Please help!

    PS: if i enter manually '8.3', excel correctly format cell as '8.03.00'...

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Enter hours.minute in cell via VBA code

    You would use:

    Please Login or Register  to view this content.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    07-15-2011
    Location
    Italy
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Enter hours.minute in cell via VBA code

    Quote Originally Posted by Domski View Post
    You would use:

    Please Login or Register  to view this content.

    Dom
    THXX!!! Works fine
    But I don't understand why if I type 8.03 in the sheet excel format the cell in the right way.

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Enter hours.minute in cell via VBA code

    Times in Excel are stored as decimal fractions with one hour being the equivalent of 1/24 so Excel is interpreting 8.3 as being the equivalent of 199.2 hours.

    Dom
    Last edited by Domski; 07-15-2011 at 05:52 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1