1

I hope this question is not too trivial as I am new to VBA.

I want to make a label in a userform show data from a cell on a worksheet. The label should show this data directly when the userform opens.

This thread probably gives me the answer:

In an Excel UserForm, how do I update a label's caption?

However I am confused regarding WHERE to put this code?!

Should I put it into the Userform directly? -> this would make the most sense to me but does not work, as the code is not even executed then. Should I create a new module for this code? -> then how do I call this sub automatically after the userform opens?

Thanks alot in advance! Leo

Ardnic
  • 51
  • 7
  • When do you want the userform to open? When you enter a value in a cell? – RCL Jan 09 '19 at 20:42
  • No. The Userform opens, once a specific button on a previously shown userform is clicked. – Ardnic Jan 09 '19 at 20:49
  • So you have 2 Userforms? The first one shows and there is a button on it and if you click it, it will show Form2? In that case `Private Sub CommandButton1_Click() Form2.label1.caption = CellValue form2.show End Sub` In this case you just need to reference the cell correctly and you should get the value. Give it a go and show us what you have tried, the code and if you get stuck we can help you. – RCL Jan 09 '19 at 20:58
  • That works perfectly! Thank you so much! :) – Ardnic Jan 09 '19 at 21:07

1 Answers1

0

Posting comment answer here so this post can be marked as answered.

Private Sub CommandButton1_Click() 
 Form2.label1.caption = CellValue 
 form2.show 
End Sub
RCL
  • 276
  • 3
  • 8