• Time averaging using Excel VBA

    Author
    Topic
    #1774019

    Good day Experts ! Hope all is fine for you,
    Here I go again for my second question in this forum.

    So basically, I am looking for help for a piece of code I wrote to average some cells that contains data in kind of time format “xx:xx”. This data actually reflects a continuous period of time but not hours or actual time (I mean not 12:00PM, but for example 03:05 would mean 3hrs and 5mins of writing, working… or whatever). Excel actually shows me the value I want to see in the lower bar, and the spreadsheet function =AVERAGE(…) gives me also the correct value (see the attached snapshot). But when I try to do it using VBA with the below code, I always get the same result : 00:00 for 12:00 AM.

    Could you please help on this?
    Thanks in advance,

    Code:
        Sheets(“Input”).Select
        Range(“AC11”).Select
        Range(Selection, Selection.End(xlDown)).Select
        avgtime = WorksheetFunction.Average(Selection)
        
        Sheets(“Output”).Activate
        ActiveSheet.Rows(LAST).Select
        ActiveSheet.Cells(ActiveCell.Row, 1).Select
        Selection.Offset(1, 0).Select
        ActiveCell.Offset(0, 29).Value = avgtime
    
    Reply To: Time averaging using Excel VBA

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: