I have a spreadsheet with 4 Sheets in atm.
"Home" "Create Order" "Supplier List" "Products"
On my "Create Order" Sheet I have a Button to open a userform to add a new product. I have a combo box which allows me to select the Supplier too. This works fine. What I am looking for is rather than me having to remember the last Product number, I was hoping to create an Auto Number system. mry code for the userform is below:
Any help would be greatly appreciated
"Home" "Create Order" "Supplier List" "Products"
On my "Create Order" Sheet I have a Button to open a userform to add a new product. I have a combo box which allows me to select the Supplier too. This works fine. What I am looking for is rather than me having to remember the last Product number, I was hoping to create an Auto Number system. mry code for the userform is below:
Code:
Private Sub cmdAdd_Click()
Dim iRow As Long
Dim lPart As Long
Dim ws As Worksheet
Set ws = Worksheets("Products")
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
.End(xlUp).Offset(1, 0).Row
lPart = Me.txtSupplier.ListIndex
'check for a product number
If Trim(Me.txtProduct.Value) = "" Then
Me.txtProduct.SetFocus
MsgBox "Please enter a product number"
Exit Sub
End If
'copy the data to the database
With ws
.Cells(iRow, 1).Value = Me.txtProduct.Value
.Cells(iRow, 2).Value = Me.txtProductName.Value
.Cells(lRow, 3).Value = Me.txtSupplier.Value
.Cells(iRow, 4).Value = Me.txtSupplier.List(lPart, 1)
.Cells(iRow, 5).Value = Me.txtDate.Value
.Cells(iRow, 6).Value = Me.txtCost.Value
.Cells(iRow, 7).Value = Me.txtQuantity.Value
.Cells(iRow, 8).Value = Me.txtQuantityPerLot.Value
End With
'clear the data
Me.txtProduct.Value = ""
Me.txtProductName.Value = ""
Me.txtSupplier.Value = ""
Me.txtDate.Value = Format(Date, "Medium Date")
Me.txtCost.Value = ""
Me.txtQuantity.Value = ""
Me.txtQuantityPerLot.Value = ""
Me.txtProduct.SetFocus
End Sub
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub UserForm_Initialize()
Dim cPart As Range
Dim ws As Worksheet
Set ws = Worksheets("Supplier List")
For Each cPart In ws.Range("SupplierID")
With Me.txtSupplier
.AddItem cPart.Value
.List(.ListCount - 1, 1) = cPart.Offset(0, 1).Value
End With
Next cPart
Me.txtProduct.Value = ""
Me.txtProductName.Value = ""
Me.txtDate.Value = Format(Date, "Medium Date")
Me.txtCost.Value = ""
Me.txtQuantity.Value = ""
Me.txtQuantityPerLot.Value = ""
Me.txtProduct.SetFocus
End Sub
Any help would be greatly appreciated