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

Why not enter the formula with code

Sub test()
Dim sh As Worksheet
For Each sh In ActiveWorkbook.Worksheets
With sh.Range("A1")
.Formula = "=lr()"
'.Value = .Value
End With
Next sh
End Sub

Have you try the other function ?
This one is working correct


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


"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