Transfer Data from texbox in userform to another textbox in other userform

inactiveUser214710

Board Regular
Joined
Apr 27, 2012
Messages
171
Again Hi everyone
I have a combo box (cbo1); text box (txt1); text box (txt2) and command box (cmd1) in userform2.

and I have another userform (userform1) where I have a text box (txtobs) and a text box (txtVal).

The objective is: 1 - the cbo1 data in userform2, after selecting the item, goes to userform1's txtobs.

2 - the same as txt2 in userform2, after being entered, goes to txtVal of userform1.

3 - in txt1 in the user2 form, the text in this box completes the information of the cbo1, in the txtobs of form1.

*** and here I need your help.

with the code below, solved (1 and 2), but with objective 3, I don't know how to do it.

Please thank you very much for your help.
VBA Code:
Private Sub cbo1_Change()



Dim i As Long, lastrow As Long, ws As Worksheet

Set ws = Sheets("tabs2")

lastrow = ws.Range("A" & Rows.count).End(xlUp).Row

For i = 2 To lastrow

If Me.cbo1.Value = ws.Cells(i, "f") Then

UserForm1.txtobs = ws.Cells(i, "f").Value & " - " '& ***

End If

Next i



End Sub



Private Sub cmdTransf_Click()

UserForm1.txtval.Value = Me.txt2.Value

Unload Me

End Sub



Private Sub UserForm_Initialize()



Dim i As Long, lastrow As Long, ws As Worksheet

Set ws = Sheets("tabs2")

lastrow = ws.Range("f" & Rows.count).End(xlUp).Row

For i = 2 To lastrow

Me.cbo1.AddItem ws.Cells(i, "f").Value

Next i

End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Maybe you need this?

VBA Code:
UserForm1.txtobs = ws.Cells(i, "f").Value & " - " & userform2.txt1.Value
 
Upvote 0
Hi Thanks
Combobox => cbo; Userform => usf; Textbox => txt

Through userform (usf1):
I have: cbo (Car brands) => cboM;
txt (notes) => txtOb

In that cbo one of the items opens another form (usf2) with:
cbo (models) => cbo1
txt (references) => txt1
txt (€ values) => txt2

The objective is to add to the txtOb information of (usf1) + txt1 information of (usf2). (Notes + references). It's the part I can't get.
=========
In the cbo above (cboM of usf1) the items camesw from a table in excel. When open, some specifications are filled in txt1, and the transfer command is automatically entered in txtOb in usf1. It is here to add the entered specifications notxt1, which I don't know.
The proposal you gave me had previously tried without success.
 
Upvote 0
I don't see any example.
Could you explain with examples, that is, exactly what data do you have in your controls and what data do you want in the controls?

That is, exactly what data do you have at the time of executing this line

UserForm1.txtobs = ws.Cells(i, "f").Value & " - " & userform2.txt1.Value

That is, exactly what data do you have in txt1 on userform2?
 
Upvote 0
Hi Dante

I hope it is enough as an example of what is intended. in other words, usf1's txtobs should contain two pieces of information, the ones in cbo1 and txt1, both of usf2
Thank you

VBA Code:
''Userfom1
' cboM =type of vehicles; txtobs =Must receive information from cbo1 and txt1 of Usf2; txtVal = amount €

Private Sub cboM_Change()

With cboM
  Select Case cboM.Value  
    Case "Cars"
       UserForm2.Show
  End Select            
End With
End Sub

Private Sub UserForm_Initialize()
 cboM.List = Array("Cars", "tractors", "Machinery")

End Sub

VBA Code:
'' Userform2
' cbo1 =Models; txt1 =Especification; txt2 =Values; cmdTransf =go to Userform1

Private Sub cbo1_Change()

Dim i As Long, lastrow As Long, ws As Worksheet
Set ws = Sheets("sheet1")             ''Sheet1 table with car brands
lastrow = ws.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To lastrow
If Me.cbo1 = ws.Cells(i, "a") Then
UserForm1.txtObs = ws.Cells(i, "a").Value & " - " & UserForm2.txt1.Value  '***

End If
Next i

End Sub

Private Sub cmdTransf_Click()
UserForm1.txtVal.Value = Me.txt2.Value
Unload Me
End Sub

Private Sub UserForm_Initialize()

Dim i As Long, lastrow As Long, ws As Worksheet
Set ws = Sheets("sheet1")
lastrow = ws.Range("a" & Rows.Count).End(xlUp).Row
For i = 2 To lastrow
Me.cbo1.AddItem ws.Cells(i, "a").Value
Next i

End Sub
 
Upvote 0
Sorry, but now I don't understand.
Where do you have the problem?

And I don't see examples with data.

I only see code, but you are not putting the data you have in each userform control.
It means that the textboxes are empty and if they are empty then you are passing a empty from one userform to another and that is why there is nothing in the target userform.
 
Upvote 0
Hi Dante
Sorry again
if I select cboM "cars", usf2 will be opened, and then I select cbo1 to choose the model of the car and txt1 for fill up some especifications.
When operating cmdTransfer, the usf1 are open and txtobs
must have the choice of cbo1 and what was written in txt1, both in usf2.
I filled in the usf1 and usf2 and is ok but the value of txt1 didn't apeared
Now if code control is necessary, I don't know. So help me please.
Jdcar
 
Upvote 0
Sorry, but you still don't tell me where you have the problem.
The problem is in this line?
UserForm1.txtObs = ws.Cells(i, "a").Value & " - " & UserForm2.txt1.Value '***

What data do you have in the UserForm2.txt1 when you execute that line?
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,199
Members
449,072
Latest member
DW Draft

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