Hello, need some help please!
I have a userform to enter data on a table. I'm in need of having the code search column "H" to find the highest number/value and then place the next highest number/value in the cell "H" of the row that the userform is entering data to. (I hope that makes sense)
I currently don't have any field on the the userform to input that "next highest value"...I was hoping it would do it in the background so the user doesn't have to do an additional step.
I also thought maybe it can perform that lookup when the form is initialized before entering any data? and it can display that number on the user form.... I'm not sure what's easier.
Here is the code for the userform. Any input would be great!!
I have a userform to enter data on a table. I'm in need of having the code search column "H" to find the highest number/value and then place the next highest number/value in the cell "H" of the row that the userform is entering data to. (I hope that makes sense)
I currently don't have any field on the the userform to input that "next highest value"...I was hoping it would do it in the background so the user doesn't have to do an additional step.
I also thought maybe it can perform that lookup when the form is initialized before entering any data? and it can display that number on the user form.... I'm not sure what's easier.
Here is the code for the userform. Any input would be great!!
Code:
Private Sub cmdSaveItem_Click()
Sheets("Item").Unprotect Password:="123456"
Dim ctrl As Control, LastRow As Long
LastRow = Sheets("Item").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For Each ctrl In Me.Controls
If TypeName(ctrl) = "TextBox" Or TypeName(ctrl) = "ComboBox" Then
If ctrl.Value = "" Then
MsgBox ("Please enter a value for " & ctrl.Name)
ctrl.SetFocus
Exit Sub
End If
End If
Next ctrl
Sheets("Item").Cells(LastRow + 1, 1).Resize(1, 7) = Array(txt_ItemName.Value, _
txt_ProdCodeSKU.Value, txt_VendorSelection.Value, txt_Location, txt_MaxStock.Value, txt_ReorderLevel.Value, txt_ItemStocked.Value)
For Each ctrl In Me.Controls
If TypeName(ctrl) = "TextBox" Or TypeName(ctrl) = "ComboBox" Then
ctrl.Value = ""
End If
Next ctrl
txt_ItemStocked = False
Sheets("Item").Protect Password:="123456"
End Sub
Last edited by a moderator: