Hi,
I've created a userform to help data entry over multiple sheets. Which sheets are populated are chosen by ticking check boxes. The problem I have is my code copies the information to all sheets, regardless of whether the check box is ticked or not. How do I stop this happening?
this is my code (I'm learning so this has been cobbled together and possibly long winded anyway)
Private Sub Add_Click()
'Copy input values to sheet.
Dim iRow As Long
Dim ws As Worksheet
Set ws1 = Worksheets("PR")
Set WS2 = Worksheets("TLS")
Set WS3 = Worksheets("VI MOD 1")
Set ws11 = Worksheets("VI MOD 2")
Set ws4 = Worksheets("V55 KEYING")
Set ws5 = Worksheets("V55 FULL")
Set ws6 = Worksheets("V62")
Set ws7 = Worksheets("CVT")
Set ws12 = Worksheets("KFI")
Set ws8 = Worksheets("TRIAGE")
Set ws10 = Worksheets("Drivers PRNREN")
Set ws9 = Worksheets("VI Trainers")
iRow1 = ws1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow2 = WS2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow3 = WS3.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow4 = ws4.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow5 = ws5.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow6 = ws6.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow7 = ws7.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow8 = ws8.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow9 = ws9.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow10 = ws10.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow11 = ws11.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow12 = ws12.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
If Me.PR.Value = True Then Set ws = ThisWorkbook.Sheets("PR")
With ws
ws1.Cells(iRow1, 1).Value = Me.NameBox.Value
ws1.Cells(iRow1, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.TLS.Value = True Then Set ws = ThisWorkbook.Sheets("TLS")
With ws
WS2.Cells(iRow2, 1).Value = Me.NameBox.Value
WS2.Cells(iRow2, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.VIMOD1.Value = True Then Set ws = ThisWorkbook.Sheets("VI MOD 1")
With ws
WS3.Cells(iRow3, 1).Value = Me.NameBox.Value
WS3.Cells(iRow3, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.VIMOD2 = True Then Set ws = ThisWorkbook.Sheets("VI MOD 2")
With ws
ws11.Cells(iRow11, 1).Value = Me.NameBox.Value
ws11.Cells(iRow11, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.V55KEY.Value = True Then Set ws = ThisWorkbook.Sheets("V55 KEYING")
With ws
ws4.Cells(iRow4, 1).Value = Me.NameBox.Value
ws4.Cells(iRow4, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.V55Full.Value = True Then Set ws = ThisWorkbook.Sheets("V55 FULL")
With ws
ws5.Cells(iRow5, 1).Value = Me.NameBox.Value
ws5.Cells(iRow5, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.V62.Value = True Then Set ws = ThisWorkbook.Sheets("V62")
With ws
ws6.Cells(iRow6, 1).Value = Me.NameBox.Value
ws6.Cells(iRow6, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.CVT.Value = True Then Set ws = ThisWorkbook.Sheets("CVT")
With ws
ws7.Cells(iRow7, 1).Value = Me.NameBox.Value
ws7.Cells(iRow7, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.KFI.Value = True Then Set ws = ThisWorkbook.Sheets("KFI")
With ws
ws12.Cells(iRow12, 1).Value = Me.NameBox.Value
ws12.Cells(iRow12, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.Triage.Value = True Then Set ws = ThisWorkbook.Sheets("TRIAGE")
With ws
ws8.Cells(iRow8, 1).Value = Me.NameBox.Value
ws8.Cells(iRow8, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.DRIVERSPRNREN.Value = True Then Set ws = ThisWorkbook.Sheets("DRIVERS PRNREN")
With ws
ws10.Cells(iRow10, 1).Value = Me.NameBox.Value
ws10.Cells(iRow10, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.VITrainers.Value = True Then Set ws = ThisWorkbook.Sheets("VI TRAINERS")
With ws
ws9.Cells(iRow9, 1).Value = Me.NameBox.Value
ws9.Cells(iRow9, 2).Value = Me.TextBox1.Value
Me.Hide
End With
'Clear input controls.
Me.NameBox.Value = ""
Me.TextBox1.Value = ""
End Sub
Much appreciated
I've created a userform to help data entry over multiple sheets. Which sheets are populated are chosen by ticking check boxes. The problem I have is my code copies the information to all sheets, regardless of whether the check box is ticked or not. How do I stop this happening?
this is my code (I'm learning so this has been cobbled together and possibly long winded anyway)
Private Sub Add_Click()
'Copy input values to sheet.
Dim iRow As Long
Dim ws As Worksheet
Set ws1 = Worksheets("PR")
Set WS2 = Worksheets("TLS")
Set WS3 = Worksheets("VI MOD 1")
Set ws11 = Worksheets("VI MOD 2")
Set ws4 = Worksheets("V55 KEYING")
Set ws5 = Worksheets("V55 FULL")
Set ws6 = Worksheets("V62")
Set ws7 = Worksheets("CVT")
Set ws12 = Worksheets("KFI")
Set ws8 = Worksheets("TRIAGE")
Set ws10 = Worksheets("Drivers PRNREN")
Set ws9 = Worksheets("VI Trainers")
iRow1 = ws1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow2 = WS2.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow3 = WS3.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow4 = ws4.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow5 = ws5.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow6 = ws6.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow7 = ws7.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow8 = ws8.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow9 = ws9.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow10 = ws10.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow11 = ws11.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
iRow12 = ws12.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
If Me.PR.Value = True Then Set ws = ThisWorkbook.Sheets("PR")
With ws
ws1.Cells(iRow1, 1).Value = Me.NameBox.Value
ws1.Cells(iRow1, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.TLS.Value = True Then Set ws = ThisWorkbook.Sheets("TLS")
With ws
WS2.Cells(iRow2, 1).Value = Me.NameBox.Value
WS2.Cells(iRow2, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.VIMOD1.Value = True Then Set ws = ThisWorkbook.Sheets("VI MOD 1")
With ws
WS3.Cells(iRow3, 1).Value = Me.NameBox.Value
WS3.Cells(iRow3, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.VIMOD2 = True Then Set ws = ThisWorkbook.Sheets("VI MOD 2")
With ws
ws11.Cells(iRow11, 1).Value = Me.NameBox.Value
ws11.Cells(iRow11, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.V55KEY.Value = True Then Set ws = ThisWorkbook.Sheets("V55 KEYING")
With ws
ws4.Cells(iRow4, 1).Value = Me.NameBox.Value
ws4.Cells(iRow4, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.V55Full.Value = True Then Set ws = ThisWorkbook.Sheets("V55 FULL")
With ws
ws5.Cells(iRow5, 1).Value = Me.NameBox.Value
ws5.Cells(iRow5, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.V62.Value = True Then Set ws = ThisWorkbook.Sheets("V62")
With ws
ws6.Cells(iRow6, 1).Value = Me.NameBox.Value
ws6.Cells(iRow6, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.CVT.Value = True Then Set ws = ThisWorkbook.Sheets("CVT")
With ws
ws7.Cells(iRow7, 1).Value = Me.NameBox.Value
ws7.Cells(iRow7, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.KFI.Value = True Then Set ws = ThisWorkbook.Sheets("KFI")
With ws
ws12.Cells(iRow12, 1).Value = Me.NameBox.Value
ws12.Cells(iRow12, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.Triage.Value = True Then Set ws = ThisWorkbook.Sheets("TRIAGE")
With ws
ws8.Cells(iRow8, 1).Value = Me.NameBox.Value
ws8.Cells(iRow8, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.DRIVERSPRNREN.Value = True Then Set ws = ThisWorkbook.Sheets("DRIVERS PRNREN")
With ws
ws10.Cells(iRow10, 1).Value = Me.NameBox.Value
ws10.Cells(iRow10, 2).Value = Me.TextBox1.Value
Me.Hide
End With
If Me.VITrainers.Value = True Then Set ws = ThisWorkbook.Sheets("VI TRAINERS")
With ws
ws9.Cells(iRow9, 1).Value = Me.NameBox.Value
ws9.Cells(iRow9, 2).Value = Me.TextBox1.Value
Me.Hide
End With
'Clear input controls.
Me.NameBox.Value = ""
Me.TextBox1.Value = ""
End Sub
Much appreciated