Search code examples
excelvbavariablesuserformmultipage

VBA - How to retrieve value from one TextBox and make it appear in another?


I have Userform in Excel. The first tab of the multipage has a variable called Staffwage_TextBox. Someone is expected to enter a value. I want to retrieve this value and make it appear on the next multipage in a TextBox called staffwage. I have this code so far:

Private Sub staffwage_Change()

Dim trial As String

Staffwage_TextBox.Characters.Text
staffwage = Staffwage_TextBox.Value

trial = Staffwage_TextBox.Characters.Text

End Sub

Any help would be appreciated, Thank you :)


Solution

  • If I got you right, You have a multipage and tab 1 and 2 hold a textbox and if something is entered in the first textbox, you want it to appear also in the second one.
    First things first: Elements within the multipage are treated like there is no multipage. So it doesn't matter where they are.

    While I'm confused by: ...a variable called Staffwage_TextBox.... I'm sure that is an object.

    To make it as easy as possible I will use different names.
    I created a multipage and added a textbox at both pages. Named TextBox1 (at page 1) and TextBox2 (at page 2). Now I double click TextBox1 and get moved to the sub for a change event (looks like you are at this point). Now I simply put in there:

    TextBox2.Value = TextBox1.Value
    

    And that is all. If i now put anything in the first text box, then the second one will have the same text. (Only works in that direction)