I have a workbook I'm working on for our IT inventory.
I need it to look for the value of ItemName. If it finds it, move one cell to the right and add the value entered by the user to the existing value in that cell.
If it doesn't find an equal value for ItemName, I need it to find the first empty cell in column A, then input all 3 values entered by the user:
ItemName
Qty
Location
I can't get it to go past looking for a duplicate ItemName.
Link to download the file:
Here
Option Explicit
'Define variables
Dim ItemName As String
Dim Qty As String
Dim Location As String
Dim ExistQty
Dim r As Long
'Initialize UserForm and calls to Subs
Private Sub UserForm_Initialize()
Call ComboBox1_Change
Call ComboBox2_Change
Call ComboBox3_Change
End Sub
'Submit data gathered to inventory
Private Sub CommandButton1_Click()
Worksheets("Data Entry").Activate
Range("A2").Activate
Do While IsEmpty(ActiveCell) = False
If ActiveCell = ItemName Then
ActiveCell.Offset(0, 1).Select
ExistQty = ActiveCell
ActiveCell = Qty + ExistQty
GoTo LastLine
Else
Do Until IsEmpty(ActiveCell) = True
Worksheets("Data Entry").Activate
Range("A2").Activate
ActiveCell.Offset(1, 0).Select
r = r + 1
GoTo NextLine
Loop
End If
Loop
NextLine:
Worksheets("Data Entry").Activate
ActiveCell.Value = ItemName
Worksheets("Data Entry").Activate
ActiveCell.Offset(0, 1).Activate
ActiveCell.Value = Qty
Worksheets("Data Entry").Activate
ActiveCell.Offset(0, 1).Activate
ActiveCell.Value = Location
Worksheets("Data Entry").Activate
ActiveCell.Offset(1, -2).Activate
LastLine:
Worksheets("Main").Activate
End Sub
'Cancel button to end process
Private Sub CancelButton_Click()
Unload Me
Worksheets("Main").Activate
End Sub
'Drop down for Item Name
Private Sub ComboBox1_Change()
Worksheets("Totals").Activate
With Worksheets("Totals").Range("A1").CurrentRegion
ComboBox1.ColumnCount = 1
ComboBox1.ColumnHeads = False
ComboBox1.RowSource = .Offset(1, 0). _
Resize(.Rows.Count, .Columns.Count).Address
End With
ItemName = Me.ComboBox1.Value
End Sub
'Drop down for Location
Private Sub ComboBox2_Change()
Worksheets("Quantity").Activate
With Worksheets("Quantity").Range("A1").CurrentRegion
ComboBox2.ColumnCount = 1
ComboBox2.ColumnHeads = False
ComboBox2.RowSource = .Offset(1, 0). _
Resize(.Rows.Count, .Columns.Count).Address
End With
Qty = Me.ComboBox2.Value
End Sub
'Drop down for Quantity
Private Sub ComboBox3_Change()
Worksheets("Location").Activate
With Worksheets("Location").Range("A1").CurrentRegion
ComboBox3.ColumnCount = 1
ComboBox3.ColumnHeads = False
ComboBox3.RowSource = .Offset(1, 0). _
Resize(.Rows.Count, .Columns.Count).Address
End With
Location = Me.ComboBox3.Value
Worksheets("Data Entry").Activate
End Sub
Bookmarks