Home » excel » excel – Dynamic Range Setting

excel – Dynamic Range Setting

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am trying to set range dynamically. However, I have faced some error:

Function call on left-hand side of assignment must return Variant or Object.

Sub calDailyGC()

    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
    Dim Rng As Range

    numGC = Cells(46, 7).Value
    numDays = Cells(47, 7).Value

    Debug.Print numGC
    Debug.Print numDays

    For k = 3 To numDays + 1
        Set Rng = Range(Cells(k, 12), Cells(k, 9999))
        sumRate = 0
        For j = 1 To numGC
            rate = Application.WorksheetFunction.Large(Rng, j)
            sumRate = sumRate + rate
        Next j
        avgGCRate = sumRate / numGC
    Next k
    Debug.Print avgGCRate

End Sub
How to&Answers:

Function call on left-hand side of assignment must return Variant or Object.

rate = Application.WorksheetFunction.Large(Rng, j)

Do not use Rate. It is a reserved word in VBA. You can read about Rate here

Change it to say

LargeVal = Application.WorksheetFunction.Large(Rng, j)