Hello chromedude,
One form is now used to for new sales on any worksheet. You only need to have the "New Sale" button call the "NewSale" macro. The attached worksbook has all the changes made to it.The biggest code change was to your "Finish" button. Here is the code...
Private Sub finishbutton1_Click()
Dim Ctrl As MSForms.Control
Dim CtrlName As String
Dim LastRow As Range
Dim NextRow As Range
Dim RowCount As Long
Dim Msgs As Variant
' Check user input
For Each Ctrl In Me.Controls
If TypeName(Ctrl) = "TextBox" Or TypeName(Ctrl) = "ComboBox" Then
CtrlName = Ctrl.Name
Msgs = Switch(CtrlName = "facilitytxt1", "Please enter a Facility.", _
CtrlName = "Unittxt1", "Please choose a Unit Type.", _
CtrlName = "modeltxt1", "Please enter a Model Number.", _
CtrlName = "quantitytxt1", "Please enter a Quantity.", _
CtrlName = "ordertxt1", "Please enter a Order Total.", _
CtrlName = "salespersontxt1", "Please enter a Salesperson.")
If Not IsNull(Msgs) And Ctrl.Value = "" Then
MsgBox Msgs, vbExclamation, "New Sale Form"
Ctrl.SetFocus
Exit Sub
End If
End If
Next Ctrl
' Write data to worksheet
Set LastRow = Cells(Rows.Count, "E").End(xlUp)
Set NextRow = IIf(LastRow.Row < 6, Cells(6, "E"), LastRow.Offset(1, 0))
Set NextRow = NextRow.Resize(ColumnSize:=7)
NextRow.Value = Array(Datetxt1, facilitytxt1, Unittxt1, modeltxt1, _
quantitytxt1, ordertxt1, salespersontxt1)
' Clear the form
For Each Ctrl In Me.Controls
If TypeName(Ctrl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
Ctrl.Value = ""
End If
Next Ctrl
Unload Me
End Sub
Bookmarks