ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Udf (https://www.excelbanter.com/excel-programming/359678-udf.html)

kontraa

Udf
 

Please,
i need this function to return formula to cell...not the value but
the formula...
thanks a lot

Public Function fnMonth(i As Integer)
fnMonth = "=Podklady!B" & 114 + i
End Functio

--
kontra
-----------------------------------------------------------------------
kontraa's Profile: http://www.excelforum.com/member.php...fo&userid=3302
View this thread: http://www.excelforum.com/showthread.php?threadid=53585


Bob Phillips[_6_]

Udf
 
Can't do it, that is altering the cell and a function cannot do that. You
could try an event procedure.

'-----------------------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
'-----------------------------------------------------------------
Const WS_RANGE As String = "H1:H10"

On Error GoTo ws_exit:
Application.EnableEvents = False
If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
If IsNumeric(.Value) Then
.Formula = "=Podklady!B" & 114 + .Value
End If
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"kontraa" wrote in
message ...

Please,
i need this function to return formula to cell...not the value but
the formula...
thanks a lot

Public Function fnMonth(i As Integer)
fnMonth = "=Podklady!B" & 114 + i
End Function


--
kontraa
------------------------------------------------------------------------
kontraa's Profile:

http://www.excelforum.com/member.php...o&userid=33028
View this thread: http://www.excelforum.com/showthread...hreadid=535859




NickHK

Udf
 
kontraa,
Is this what you mean ?

In sheet1, range A1=GetFormula(5)

Public Function GetFormula(argOffset As Long) As String
With Sheet2.Range("A1")
GetFormula = .Offset(argOffset, 1).Formula
End With
End Function

But I suspect there are better way of achieving your goal.

NickHK

"kontraa" wrote in
message ...

Please,
i need this function to return formula to cell...not the value but
the formula...
thanks a lot

Public Function fnMonth(i As Integer)
fnMonth = "=Podklady!B" & 114 + i
End Function


--
kontraa
------------------------------------------------------------------------
kontraa's Profile:

http://www.excelforum.com/member.php...o&userid=33028
View this thread: http://www.excelforum.com/showthread...hreadid=535859





All times are GMT +1. The time now is 03:07 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com