Only one cell is ever "Active" so your UDF in it's present form can only ever return the string for the active cell, you need therefore to pass a range reference to the UDF so it knows to which data it should be referring when generating the string, eg:
Function rate1(rngValues As Range) As String
Dim rngCell As Range
For Each rngCell In rngValues.Cells
If rngCell.Value <> "" Then rate1 = rate1 & "+" & rngCell & "*" & rngCell.Offset(4 - rngCell.Row)
Next rngCell
rate1 = Replace(rate1, "+", "", 1, 1)
End Function
Called from your cell as:
M5: =RATE1(B5:K5)
copied down
You could do the same thing with native functions if preferred...
=REPLACE(REPT("+"&B5&"*"&B$4,B5<>"")&REPT("+"&C5&"*"&C$4,C5<>"")&REPT("+"&D5&"*"&D$4,D5<>"")&REPT("+"&E5&"*"&E$4,E5<>"")&REPT("+"&F5&"*"&F$4,F5<>"")&REPT("+"&G5&"*"&G$4,G5<>"")&REPT("+"&H5&"*"&H$4,H5<>"")&REPT("+"&I5&"*"&I$4,I5<>"")&REPT("+"&J5&"*"&J$4,J5<>"")&REPT("+"&K5&"*"&K$4,K5<>""),1,1,"")
Bookmarks