+ Reply to Thread
Results 1 to 1 of 1

VBA Function averaging values for certain periods of dates not working anymore

  1. #1
    Registered User
    Join Date
    03-29-2012
    Location
    Santiago de Chile
    MS-Off Ver
    Excel 2007
    Posts
    36

    VBA Function averaging values for certain periods of dates not working anymore

    For the following user defined function "averagefordates" i receive #Value Error. It worked 2 hours ago but i am not able to resolve it. Any help highly appreciated.

    Function average values for certain specific dates



    Public Function averagefordates(datecol As Range, valuecol As Range, date1 As Date, date2 As Date) As Double
    Dim dx, vx, sumx As Double, countx As Long, i As Long
    On Error GoTo errhdl
    dx = datecol.Value
    vx = valuecol.Value
    If UBound(dx, 1) <> UBound(vx, 1) Then GoTo errhdl
    For i = 1 To UBound(dx, 1)
    If dx(i, 1) = "" Or IsEmpty(dx(i, 1)) Then
    Else
    If dx(i, 1) >= date1 And dx(i, 1) <= date2 Then
    sumx = sumx + vx(i, 1)
    countx = countx + 1
    End If
    End If

    Next i
    averagefordates = 0
    If countx > 0 Then
    averagefordates = sumx / countx
    End If

    normal_exit:
    Exit Function
    errhdl:
    averagefordates = "error"
    GoTo normal_exit

    End Function
    Attached Files Attached Files
    Last edited by slacknoise; 07-09-2014 at 05:05 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Averaging values if desired dates fall between range of dates
    By gbcpurdue in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-21-2012, 02:51 PM
  2. Replies: 1
    Last Post: 05-17-2006, 05:35 AM
  3. Averaging Values between Two Dates/Times
    By ChrisM in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 11-15-2005, 11:20 PM
  4. Averaging values between two dates/times
    By ChrisM in forum Excel General
    Replies: 1
    Last Post: 11-14-2005, 11:30 AM
  5. Averaging Values between Two Dates/Times
    By ChrisM in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-14-2005, 11:15 AM

Tags for this Thread

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