View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Gwen Gwen is offline
external usenet poster
 
Posts: 54
Default How do I enter a function in a cell and run it programmaticall

Thanks, =lr() works fine when I entered it manually.
But I needed a way to get that function in a cell programatically.

"Don Guillett" wrote:

I may be misunderstanding what you want but did you look at my previous
answer

=lr()

--
Don Guillett
SalesAid Software

"Gwen" wrote in message
...
I am trying to do something like this:

range("A1").value = lr()

It doesn't work.
Harlan's Function:

Function lr(Optional r As Range) As Variant
Dim ur As Range, c As Range, i As Long, n As Long

'there arguments for & against volatility - optional to uncomment
Application.Volatile

If r Is Nothing Then Set r = Application.Caller
If Not TypeOf r Is Range Then Set r = ActiveCell

Set ur = r.Parent.UsedRange
n = ur.Rows.Count

For i = n To 1 Step -1
Set c = ur.Cells(i, 1)
If Not IsEmpty(c.Value) Then Exit For
If Not IsEmpty(c.End(xlToRight).Value) Then Exit For
Next i

lr = ur.Row + i - 1
End Function



"Ron de Bruin" wrote:

Which function ?

See your other thread


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Gwen" wrote in message
...
Please assist.
I have been trying to place the function in cell A1 fo every sheet and
run
it programmatically?
The function is in a module.

Thanks