2

How can I put the Excel formula into the textbox?

I tried sth like this:

 Sub CivBox()
  With ActiveSheet
   .Shapes("Civils 3").Copy
   [C26].Activate
   .Paste
   .Shapes(.Shapes.Count).Name = "Civils 4"
   .Shapes("Civils 4").TextFrame2.TextRange.Characters.Text = "=D51"
 End With
End Sub

But the only the string is returned

enter image description here

Is it possible to put the Excel formula into the textBox or shall I prepare it in some cell first, and next link this cell into this textbox as a range?


2 Answers 2

5

If you're using a Shape you could use this

Sub x()

ActiveSheet.Shapes(1).OLEFormat.Object.Formula = "=A1"

End Sub

For a textbox you can use

ActiveSheet.TextBoxes("TextBox 1").Formula = "=A1"
Sign up to request clarification or add additional context in comments.

Comments

1

You can do this indirectly. You can't put it IN the box, but you can select the textbox (not the contents of the textbox), go to the formula bar, and reference a cell.

Edit: This might help: https://www.solveyourtech.com/how-to-display-a-formula-result-in-a-text-box-in-excel-2010/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.