Using VBA to link the contents of two text boxes

RedMan7

New Member
Joined
Feb 15, 2019
Messages
20
Hello All!

I hope this message finds you well and that you are able to assist me. I am attempting to link the contents of one text box to another text box in excel - to be clear, I don't want to link the contents of a cell to another text box, and I purposefully would like to do it using VBA because I have never used VBA and would like to learn how to.

I have found this answer on StackOverflow and would appreciate it if anyone could guide me through doing this on excel as I have never used VBA before.

Thank you all!

https://stackoverflow.com/questions...he-textbox-in-other-textboxes-on-other-sheets


Create a module, and place this code there. This needs to be configured for your own specific textbox names and sheet names
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Public Sub UpdateTextBoxes(str As String)

Sheets
("sheet1").TextBox1.Text = str
Sheets
("sheet2").TextBox1.Text = str
Sheets
("sheet3").TextBox1.Text = str
End Sub</code>Then for each textbox object you wish to replicate, use this for its change event (Sheet Class Module) (Change the paramaters to suite your needs)
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; box-sizing: inherit; white-space: inherit;">Private Sub TextBox1_Change()
UpdateTextBoxes
Me.TextBox1.Text
End Sub</code>This way you can name your controls however you see fit, and you can update the text from any of the textboxes, and they will always be consistant.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
The other person that posted those SUBS took an extra step that may or may not be necessary. I created two ActiveX Text boxes on a sheet. When I'm in Design Mode (active) under the Developer Tab, I can double click the edges of textbox1 and it takes me to VBA and creates the SUB below. I just wrote a simple line that makes textbox2 have the same text as textbox1 in real time.

What other questions do you have?

Code:
Private Sub TextBox1_Change()
    TextBox2.Text = TextBox1.Text
End Sub
 
Upvote 0
Hi Jeffrey,

Thanks for your reply. I am aware of VBA and its benefits, I just don't know how to implement this code - I'm just looking for instructions on how to do this. Would you be able to show me how to implement this step by step?

Thanks
 
Upvote 0
Silentwolf is mostly right. It would take many back and forth posts to get you where you need to be to understand the process I described in three sentences.

* Find out how to make your Developer Tab visible on the Ribbon menu; hint: File - Options - Customize Ribbon
* Learn how to create an ActiveX control; hint: Developer - Insert
* Learn the differences of Sheet Modules and Standard Modules in the VBA; ALT-F11


After you create the two ActiveX Text Boxes. Post a question to me in this thread and I will continue to help.

Jeff
 
Upvote 0
Hi All,

I've done exactly what you said, and when exiting Design Mode (clicking on the design mode button) and typing into text box 1, I get an error saying: Runtime Error 424 Object Required...

Am I missing something? Thanks!
 
Upvote 0
So.... You created two textboxes? When you created the textboxes you chose ActiveX textboxes?

On the formula bar, all the way to the left, the name bar will display the name of each textbox when you select the textbox in Design Mode. Do you see Textbox1 and textbox2?

After you have confirmed the names, you need double click on Textbox1 so that it brings you to the VBA window and creates a SUB called Private Sub TextBox1_Change(). If that is done and you have added the code from my post #2 , then it should work.

The error above, I believe is an error that is caused by the code trying to make Textbox2 have the same text as Textbox1. If Textbox2 doesn't exists, then I would expect that error.

Still committed to help.

Jeff
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top