0

I have got a userform which provides data for a macro. Once this macro is complete i would like to paste the values which were inputted in the userform to cells, with the use of a button. I have read that the userform cannot be unloaded which i dont think mine is as to close the userform i use the code:

userform1.hide
userform2.show

and then to close userform two i use the code:

userform2.hide

Also, when i open the userform back up the values that i have inputted remain.

The code i am using to try and print values from the text box is:

Sub copypaste2()

'code to copy and paste a graph and some text, using the macro recorder
 ActiveSheet.ChartObjects("Chart 1").Activate
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Copy
Sheets("Sheet1").Select
ActiveSheet.Pictures.Paste.Select
Sheets("sheet2").Select
Range("B7:G9").Select
Selection.Copy
Sheets("Sheet1").Select
Range("M5").Select
ActiveSheet.Paste
Range("K6").Select

'code to paste value from userform textbox to cell
Worksheets("sheet1").Range("M8").Value = UserForm1.baseflowtextbox.Value

end sub
  • *I have read that the userform cannot be unloaded* - huh? UserForm default instances are pretty much the only thing `Unload` can work with. If you can read from the textbox by accessing `UserForm1.baseflowtextbox.Value` on the right-hand side of an assignment expression, have you tried putting `UserForm1.baseflowtextbox.Value` on the left-hand side of an assignment? – Mathieu Guindon Apr 17 '19 at 15:29
  • I'm not sure from your question if the issue is that the textbox still contains the value, or if the issue is that the worksheet isn't getting it.... – Mistella Apr 17 '19 at 15:29
  • *when i open the userform back up the values that i have inputted remain.* - is that expected? You're working off the form's default instance, so its state is essentially global, and if you aren't unloading the form then its state is preserved between `Show` member calls (unless the form is destroyed when the user clicks the X button in the form's control box).. In any case, I'd recommend reading [this post about `Select` & `Activate`](https://stackoverflow.com/q/10714251/1188513). – Mathieu Guindon Apr 17 '19 at 15:34
  • @mathieu Im sure i tried that yesterday however, when i tried it again it worked! haha. Thanks for your time its appreciated. In reference to your first comment. – dingle ben Apr 17 '19 at 15:36

0 Answers0