+ Reply to Thread
Results 1 to 3 of 3

Udf

  1. #1
    Registered User
    Join Date
    03-31-2006
    Posts
    4

    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 Function

  2. #2
    Bob Phillips
    Guest

    Re: 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" <[email protected]> wrote in
    message news:[email protected]...
    >
    > 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
    >




  3. #3
    NickHK
    Guest

    Re: 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" <[email protected]> wrote in
    message news:[email protected]...
    >
    > 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
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1