问题
I have a userform which looks like this
All the textboxes are filled with default values once a user opens this form.
The user then changes the values manually and presses OK which will close the form and will affect the charts linked to the form.
If the user opens the form again, the values in the textboxes revert back to default ones and the charts linked will assume their default positions too.
Is there any way where once the user presses OK, the values in the userform gets saved so when the user opens the form the next time, they are presented with the changed values instead of the default ones??
Thanks!
回答1:
Have you tried using the Sheet as a place to save the data?
Dim i As Integer
Private Sub UserForm_Initialize()
For i = 1 To 49 'Number of TextBoxes (I counted 49)
Controls("TextBox" & i).Text = Cells(i, 1)
Next i
End Sub
Private Sub CommandButton1_Click() 'Save button
For i = 1 To 49
Cells(i, 1) = Controls("TextBox" & i).Text
Next i
End Sub
This will save the values in the first 49 rows of the first coloumn. If you want to save it to an other Sheet, create a new one and add Worksheets("SheetName").Cells...
.
来源:https://stackoverflow.com/questions/38301749/how-to-save-the-values-in-a-userform-in-vba