Consulting

Results 1 to 6 of 6

Thread: Recording time spent on a worksheet

  1. #1
    VBAX Contributor samohtwerdna's Avatar
    Joined
    Dec 2004
    Location
    Denver Colorado
    Posts
    143
    Location

    Recording time spent on a worksheet

    OK, another simple question for the masters

    I want to record the time spent on a worksheet. For now I think I would like to gage from worksheet open to print - but I could also start with entry into the A9 cell.

    Will I need to place the code into Worksheet_SelectionChanged or Worksheet_Print(if this exists) Then how do I retreive a time? I thought I could use Now() but this is a little more info than I need.

    Any suggestions??
    To live is Christ... To code is cool!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by samohtwerdna
    OK, another simple question for the masters

    I want to record the time spent on a worksheet. For now I think I would like to gage from worksheet open to print - but I could also start with entry into the A9 cell.

    Will I need to place the code into Worksheet_SelectionChanged or Worksheet_Print(if this exists) Then how do I retreive a time? I thought I could use Now() but this is a little more info than I need.

    Any suggestions??

    [vba]
    Option Explicit

    Private nTime As Date

    Private Sub Workbook_BeforePrint(Cancel As Boolean)
    MsgBox "Time used so far: " & Format(Now - nTime, "hh:mm:ss")
    End Sub

    Private Sub Workbook_Open()
    nTime = Now
    End Sub
    [/vba]

    'This is workbook event code.
    'To input this code, right click on the Excel icon on the worksheet
    '(or next to the File menu if you maximise your workbooks),
    'select View Code from the menu, and paste the code
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Contributor samohtwerdna's Avatar
    Joined
    Dec 2004
    Location
    Denver Colorado
    Posts
    143
    Location
    That was way eaiser than I thought it would be!!

    Nice to know that Date just needs to be formated to get the time - (Should have known that )

    OK - now if I did want to check from entry into Range("A9") would I just change
    [VBA]
    Private Sub Workbook_Open()
    nTime = Now
    End Sub[/VBA]
    to
    [VBA]
    Private Sub Worksheets_SelectionChange(frstEnt as Range)
    frstEnt = ("A9")
    nTime = Now
    End Sub[/VBA]

    Or something like it??
    To live is Christ... To code is cool!

  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Might also be worth looking at the Journal in Outlook, which can record this information for all workbooks.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by samohtwerdna
    That was way eaiser than I thought it would be!!

    Nice to know that Date just needs to be formated to get the time - (Should have known that )

    OK - now if I did want to check from entry into Range("A9")
    Check what?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Contributor samohtwerdna's Avatar
    Joined
    Dec 2004
    Location
    Denver Colorado
    Posts
    143
    Location
    The time spent from data entry into the A9 cell to the print function
    To live is Christ... To code is cool!

Posting Permissions

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