cooper88
cooper88

Reputation: 17

VBA update userform textbox automatically

I am trying to update the userform TextBox2 "number of cells needed" with the value of C2. The user enters the number of parts in the TextBox1 and it updates the cell value A2, but I cant get it to pass the value of C2 to the other text box automatically. There is a simple formula in C2 =(A2*2)+1 but i dont think that should matter.

Private Sub TextBox1_Change()
ThisWorkbook.Worksheets("Sheet2").Range("A2").Value = TextBox1.Value 
End Sub


Private Sub TextBox2_Change()

TextBox2.txtEcpNum.Text = CStr(Range("C2").Value) 
TextBox2.Show

End Sub

enter image description here

Upvotes: 0

Views: 5240

Answers (1)

DDV
DDV

Reputation: 2395

The Textbox2_Change() event handler is not being called when Textbox1_Change() is being called. All you need to do is change Textbox2 after you change Textbox1, ie. in the same event handler. Namely:

Private Sub TextBox1_Change()

    ThisWorkbook.Worksheets("Sheet2").Range("A2").Value = TextBox1.Value
    TextBox2.txtEcpNum.Text = CStr(Range("C2").Value) 
    TextBox2.Show 

End Sub

Upvotes: 3

Related Questions