View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson Greg Wilson is offline
external usenet poster
 
Posts: 747
Default VBA Function won't work!

Try:

Function topright(values As Range) As Double
topright = values(1, values.Columns.Count) * 2
End Function

The reason your function doesn't work is because the Offset method returns a
range of cells and your function is tyring to multiply an array by a single
element (i.e. 2).

Regards,
Greg
" wrote:

Can anybody please enlighten me why this Excel VBA function* works:

Function topright(values)
topright = values.Offset(0, values.Columns.Count - 1)
End Function

and why this one does not (it alwasy returns a #VALUE! error):

Function topright(values)
topright = values.Offset(0, values.Columns.Count - 1) * 2
End Function

Help, would greatly appreciated before insanity sets in.




* this function, by the way, is supposed to find the top right hand
value in any excel range. So if, in Excel, you did =topright(A1:F5),
the function would return the value in A5.