Replace the maintenance button code with this.
Private Sub CommandButton3_Click()
Dim lRow As Long
Dim ws As Worksheet
If ComboBox1.ListIndex <> -1 Then
Set ws = Worksheets(ComboBox1.Value)
Else
MsgBox "Please select an equipment."
Exit Sub
End If
'find first empty row in database
lRow = ws.Cells(Rows.Count, 2) _
.End(xlUp).Offset(1, 0).Row
'copy the data to the database
With ws
.Cells(lRow, 2).Value = Me.TextBox1.Value
.Cells(lRow, 3).Value = "N.A"
.Cells(lRow, 12).Value = Me.cboLO.Value
.Cells(lRow, 13).Value = Me.cboSO.Value
.Cells(lRow, 14).Value = "Weekly Maintenance"
.Cells(lRow, 3).Resize(, 9).Merge
End With
Unload Me
UserForm1.Show
End Sub
Bookmarks