Cynthia465
Technical User
Hello Members
I am new to VBA Excel Programming. I created a userform to insert data by row count (Last Name, First Name, Date Completed, Discharge Date). I want to use my userform to write data to three different worksheets "Sheet1", "Sheet2", and "Sheet3". I encountered a problem with not knowing how to properly write my code to prevent my userform from copying data the belongs on "Sheet1" from copying to "Sheet2" and "Sheet3". When my userform appear in "Sheet2" the data also writes to "Sheet1" and "Sheet3". I want to insert different data for each worksheet. Below is the code that I used for cmdOK_Click()that's copying to all Worksheets. Members your help will be very much appreciated.
Private Sub cmdOK_Click()
Dim RowCount As Long
RowCount = Worksheets("Sheet1").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Sheet1").Range("A1")
.Offset(RowCount, 0).Value = Me.txtLastName.Value
.Offset(RowCount, 1).Value = Me.txtFirstName.Value
.Offset(RowCount, 2).Value = Me.txtDateCompleted.Value
.Offset(RowCount, 3).Value = Me.txtDischargeDate.Value
End With
RowCount = Worksheets("Sheet2").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Sheet2").Range("A1")
.Offset(RowCount, 0).Value = Me.txtLastName.Value
.Offset(RowCount, 1).Value = Me.txtFirstName.Value
.Offset(RowCount, 2).Value = Me.txtDateCompleted.Value
.Offset(RowCount, 3).Value = Me.txtDischargeDate.Value
End With
RowCount = Worksheets("Sheet3").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Sheet3").Range("A1")
.Offset(RowCount, 0).Value = Me.txtLastName.Value
.Offset(RowCount, 1).Value = Me.txtFirstName.Value
.Offset(RowCount, 2).Value = Me.txtDateCompleted.Value
.Offset(RowCount, 3).Value = Me.txtDischargeDate.Value
End With
End Sub
I am new to VBA Excel Programming. I created a userform to insert data by row count (Last Name, First Name, Date Completed, Discharge Date). I want to use my userform to write data to three different worksheets "Sheet1", "Sheet2", and "Sheet3". I encountered a problem with not knowing how to properly write my code to prevent my userform from copying data the belongs on "Sheet1" from copying to "Sheet2" and "Sheet3". When my userform appear in "Sheet2" the data also writes to "Sheet1" and "Sheet3". I want to insert different data for each worksheet. Below is the code that I used for cmdOK_Click()that's copying to all Worksheets. Members your help will be very much appreciated.
Private Sub cmdOK_Click()
Dim RowCount As Long
RowCount = Worksheets("Sheet1").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Sheet1").Range("A1")
.Offset(RowCount, 0).Value = Me.txtLastName.Value
.Offset(RowCount, 1).Value = Me.txtFirstName.Value
.Offset(RowCount, 2).Value = Me.txtDateCompleted.Value
.Offset(RowCount, 3).Value = Me.txtDischargeDate.Value
End With
RowCount = Worksheets("Sheet2").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Sheet2").Range("A1")
.Offset(RowCount, 0).Value = Me.txtLastName.Value
.Offset(RowCount, 1).Value = Me.txtFirstName.Value
.Offset(RowCount, 2).Value = Me.txtDateCompleted.Value
.Offset(RowCount, 3).Value = Me.txtDischargeDate.Value
End With
RowCount = Worksheets("Sheet3").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Sheet3").Range("A1")
.Offset(RowCount, 0).Value = Me.txtLastName.Value
.Offset(RowCount, 1).Value = Me.txtFirstName.Value
.Offset(RowCount, 2).Value = Me.txtDateCompleted.Value
.Offset(RowCount, 3).Value = Me.txtDischargeDate.Value
End With
End Sub