Quantcast
Channel: Active questions tagged worksheet-function - Super User
Viewing all articles
Browse latest Browse all 1009

#VALUE error on specific lines in excel, using a VBA Function

$
0
0

I'm using a function to calculate how many trips, one way or round trip, between routes. The function is working for most of the information in my sheet but I have received a #VALUE! error on a couple of groupings. I have double checked all cells: they are General format, there are no extra spaces and no special characters. What other reason could I be getting the error? I've included a screen shot of the error and a copy of the code.Any help would be appreciated. Thank you.

![enter image description here

Code:

Function CalculateDaysOfService(rng As Range, tripType As Integer) As LongDim oneWay As Long, roundTrip As Long, fullDay As LongDim week As RangeDim days(1 To 3) As LongDim i As Long, minDays As Long, midDays As Long, maxDays As LongFor Each week In rng.Columns' Get the number of days each route operated this week    For i = 1 To 3        days(i) = week.Cells(i, 1).Value    Next i' Calculate Full Days    minDays = Application.WorksheetFunction.Min(days(1), days(2), days(3))    fullDay = fullDay + minDays' Calculate Round Trips    midDays = Application.WorksheetFunction.Max( _        Application.WorksheetFunction.Min(Application.WorksheetFunction.Max(days(1) - minDays, 0), Application.WorksheetFunction.Max(days(2) - minDays, 0)), _        Application.WorksheetFunction.Min(Application.WorksheetFunction.Max(days(2) - minDays, 0), Application.WorksheetFunction.Max(days(3) - minDays, 0)), _        Application.WorksheetFunction.Min(Application.WorksheetFunction.Max(days(1) - minDays, 0), Application.WorksheetFunction.Max(days(3) - minDays, 0)))    roundTrip = roundTrip + midDays' Calculate One Way    maxDays = Application.WorksheetFunction.Max(days(1), days(2), days(3))    oneWay = oneWay + (maxDays - minDays - midDays)Next weekSelect Case tripType    Case 1: CalculateDaysOfService = oneWay    Case 2: CalculateDaysOfService = roundTrip    Case 3: CalculateDaysOfService = fullDayEnd SelectEnd Function

Viewing all articles
Browse latest Browse all 1009

Trending Articles