Weighted Average. Runtime Error: Index out of defined Range.

Function Weighted_Average(optional x(), optional w())
dim WA as double
dim SUMWX as double
dim SUM as double

    	For i = 1 to UBound(x)
    		SUMWX = SUMWX + w(i,1)*x(i,1)
    	Next i
    	
    	For b = 1 to UBound(x)
    		SUM = SUM + w(i,1)
    	Next b
    	
    	WA = SUMWX/SUM
    	Weighted_Average = WA
    	
    End Function

Please reformat into something more readable, tell us how you call that and ask a question.