Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA to copy text from two separate text boxes to one other text box 1

Status
Not open for further replies.

marshman99ca

Technical User
Apr 11, 2007
13
CA
I am trying to figure out how to copy the text that is contained in two different text boxes in an excel sheet and combine and concatenate that text into a third textbox on a different sheet in the same workbook.
Any quick code ideas would be greatly helpful.
 
Try it like this:

Worksheets("sheet2name").TextBoxName = Worksheets("sheet1name").TextBox1Name & Worksheets("sheet1name").TextBox2Name

Wim
 
Thank you much for the code, however I am running Windows Vista (not sure if that matters or not) and that code keeps giving me the debug error, saying
Here is my full code; runtime error 438, object doesn't support this object or method.
Private Sub Workbook_Open()
Worksheets("Summary Page").TextBox3 = Worksheets("Description").TextBox1 & Worksheets("Description").TextBox2
End Sub
 
I hate 438 errors... don't you?

Maybe you could try to create a new Sub, splitting the code into seperate lines, in order to isolate the problem.

Like this:

Code:
Private Sub TestSub()

  Dim t1, t2, t3

  t1 = Worksheets("Description").TextBox1
  t2 = Worksheets("Description").TextBox2
  t3 = t1 & t2
  Worksheets("Summary Page").TextBox3 = t3
 
End Sub

Don't know if this is helpful...
 
Thanks wimvh, that is a nice easy solution. Now I have a couple. but it is all valuable learning.
 
Wimvh,
I just tried your latest suggestion and it doesn't work. I get a method doesn't work with object error message. ??
 
I tried your solution with the Dim t1, t2, and I get an Error msg '9', "Subscript out of range" message??
 
Could you be having issues with the name of the textboxes? Each sheet maintain its own count.

If Sheets("Description") has two textboxes - Textbox1, Textbox2 - and Sheets("Summary Page") has one textbox, then that textbox is also Textbox1...Worksheets("Summary Page").TextBox1

Worksheets("Summary Page").TextBox3

is only valid if there indeed at least three textboxes, on THAT sheet.

BTW: this is a good reason for explicitly naming objects.

Worksheets("Summary Page").CompiledText = t3

would put the value into the textbox named CompiledText.

Also, I am not sure why you need to use variables.
Code:
  Worksheets("Summary Page").TextBox3 = Worksheets("Description").TextBox1 & _
    " " & Worksheets("Description").TextBox2
Assuming there IS a Textbox3, works fine with no use of variables.

Gerry
My paintings and sculpture
 
Gerry, I think you are on to something. The fact that textboxes on each page start being numbered again is not obvious to a newbie like me. And I am not using the variables, they didn't work.
Also, I suppose it will make a difference if the textbox properties are locked in any way?? I have remedied that.
Thank you greatly for you input. I am going to try your changes now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top