+ Reply to Thread
Results 1 to 5 of 5

Textbox text into cell as formula

  1. #1
    Zone
    Guest

    Textbox text into cell as formula

    On my userform, I have a textbox that displays a formula from a cell.
    I want to edit the formula in the textbox and, when I click OK, put the
    text back into the cell as a formula.
    activecell.formula = me.textbox1 puts it in as text. TIA, James


  2. #2
    keepITcool
    Guest

    Re: Textbox text into cell as formula

    I dont know what's in your textbox.. but
    ActiveCell.Formula = "=Sum(b1:b10)" works for me.

    Your routine must check that the string starts with "="

    NOTE:
    Personally I'd use FormulaLOCAL to interact between textbox and range.
    as this will contain the language and separators the user expects.


    --
    keepITcool
    | www.XLsupport.com | keepITcool chello nl | amsterdam


    Zone wrote in
    <news:<[email protected]>

    > On my userform, I have a textbox that displays a formula from a cell.
    > I want to edit the formula in the textbox and, when I click OK, put
    > the text back into the cell as a formula.
    > activecell.formula = me.textbox1 puts it in as text. TIA, James


  3. #3
    Tom Ogilvy
    Guest

    RE: Textbox text into cell as formula

    You code worked for me, but this did as well which might be a bit more robust:

    Private Sub CommandButton1_Click()
    Dim s As String, sf as String
    s = Trim(TextBox1.Text)
    sf = ActiveCell.Numberformat
    ActiveCell.NumberFormat = "General"
    If Left(s, 1) <> "=" Then
    s = "=" & s
    End If
    ActiveCell.Formula = s
    ActiveCell.Numberformat = sf
    End Sub

    --
    Regards,
    Tom Ogilvy



    "Zone" wrote:

    > On my userform, I have a textbox that displays a formula from a cell.
    > I want to edit the formula in the textbox and, when I click OK, put the
    > text back into the cell as a formula.
    > activecell.formula = me.textbox1 puts it in as text. TIA, James
    >
    >


  4. #4
    Tom Ogilvy
    Guest

    RE: Textbox text into cell as formula

    You code worked for me, but this did as well which might be a bit more robust:

    Private Sub CommandButton1_Click()
    Dim s As String, sf as String
    s = Trim(TextBox1.Text)
    sf = ActiveCell.Numberformat
    ActiveCell.NumberFormat = "General"
    If Left(s, 1) <> "=" Then
    s = "=" & s
    End If
    ActiveCell.Formula = s
    ActiveCell.Numberformat = sf
    End Sub

    --
    Regards,
    Tom Ogilvy



    "Zone" wrote:

    > On my userform, I have a textbox that displays a formula from a cell.
    > I want to edit the formula in the textbox and, when I click OK, put the
    > text back into the cell as a formula.
    > activecell.formula = me.textbox1 puts it in as text. TIA, James
    >
    >


  5. #5
    Zone
    Guest

    Re: Textbox text into cell as formula

    Thanks, Cool. I subsequently found that the text needed to be trimmed
    for some reason. I'll look into your suggestions, though. Cheers,
    James
    keepITcool wrote:
    > I dont know what's in your textbox.. but
    > ActiveCell.Formula = "=Sum(b1:b10)" works for me.
    >
    > Your routine must check that the string starts with "="
    >
    > NOTE:
    > Personally I'd use FormulaLOCAL to interact between textbox and range.
    > as this will contain the language and separators the user expects.
    >
    >
    > --
    > keepITcool
    > | www.XLsupport.com | keepITcool chello nl | amsterdam
    >
    >
    > Zone wrote in
    > <news:<[email protected]>
    >
    > > On my userform, I have a textbox that displays a formula from a cell.
    > > I want to edit the formula in the textbox and, when I click OK, put
    > > the text back into the cell as a formula.
    > > activecell.formula = me.textbox1 puts it in as text. TIA, James



+ 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