On 2002-09-08 06:47, dharsana wrote:...I would like to know how to use a userform for entering data and save it automatically.i.e when I open the workbook ,userform pops-up for adding data ....
In the
Workbook_Open routine,found in
ThisWorkbook there will be at least one line of code:
Userform1.Show
Userform1 is the default name for the first userform you create. You may/can change it's name to something else if you desire.
I suggest that all the code specific to the userform be kept in the userform module. If you want the current date displayed, the last line of the workbook displayed, etc. that sort of code will go in the
Userform_Initialize routine. That way, when you are designing the form and want to see how it behaves, all you do is press F5 to display it.
...which is added to sheet3(or any other sheet)...
More detail is needed. Are we speaking of fixed cells, or adding data to the first open line at the end of a list?
If you need to add data at the end of a column, one technique is to select a cell at the extreme end of the column and 'come up' to the first cell filled with data, then move down one cell.
Start the Macro Recorder, and record the code for End-UpArrowKey combinations.
Cells(65000,1).Select
Selection.End(xlUp).Select
ActiveCell.Offset(1,0).Select
Is the sanitized code for the keystrokes (when in relative reference) to find your way to the end of a column.
If I close the userform ,I should be able to work normal.
If you want a Cancel button, set it's
.Cancel property set to True, and it's
CancelButton_Click routine to include
Unload Me. Suggest you change it's codename from CommandButton1, giving you a CancelButton_Click routine.
As to when your data gets plugged into the sheet, a lot depends on your application. If you want to wait until the user presses a Done button, the
DoneButton_Click routine will have the code, or call the code.
If you desire a "Are you sure you want to exit?" message, then call that MsgBox in
UserForm_Terminate routine.
This message was edited by stevebausch on 2002-09-08 08:29