Copy / Paste from 1 userform to another

Dustan

New Member
Joined
Jun 19, 2012
Messages
47
Hello,

I am needing to do something and for the life of me, cant figure it out.

I have UserformA with TextBox1 on the userform
UserformA also has CommandButton1

when I click the CommandButton1, I want UserformB to open. I know how to do this,

Code:
Private Sub CommandButton1_Click()
Unload Me
UserformB.Show
End Sub

When UserformB opens, I want the value from TextBox1 in UserformA to be copied and pasted into TextBox22 on UserformB.

Can anyone help me with this?

Thanks in advance...
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Others may offer a better way, but this is what I would do.

Code:
Private Sub CommandButton1_Click()
    Load UserFormB
    UserFormB.TextBox22.Value = Me.TextBox1.Value
    Unload Me
    UserFormB.Show
End Sub

Hope that helps.
 
Upvote 0
Thanks for the help! Works great!!!

With a little modification to fit my application this is what the final code looks like...

Code:
Dim test1 As String
Dim FoundRange As Range
    test1 = TextBox1.Value
    Set FoundRange = Sheets("52138_RRP").Range("A:A").Find(what:=test1, LookIn:=xlFormulas, lookat:=xlWhole)
    
    If FoundRange.Offset(0, 81).Value = "Meters" Then
    Load TrayLengthm
    TrayLengthm.TextBox1.Text = Me.TextBox1.Value
    Unload Me
    TrayLengthm.Show
    End If
    If FoundRange.Offset(0, 81).Value = "Feet" Then
    Load TrayLengthft
    TrayLengthft.TextBox1.Text = Me.TextBox1.Value
    Unload Me
    TrayLengthft.Show
    End If
 
Last edited:
Upvote 0
Glad it helped. :)

As a quick note about your code, you don't have to end the first If statement. Rather, you can continue with ElseIf FoundRange.Offset(0.... = "Feet" Then....
Or, if those are the only two possibilities, you can just go straight to Else without doing an ElseIf or another If statement.

And so on. Just thought I'd throw that out there, just for some clean coding practices; doesn't affect the outcome at all.
 
Upvote 0

Forum statistics

Threads
1,219,162
Messages
6,146,660
Members
450,706
Latest member
LGVBPP

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