New Member
August 10, 2019
Hi
I am trying to create a VBA program that will allow
(1) the user to enter a list of alphanumeric values(orders) - Unique codes of each product of our company - in a user form
(2) Then on clicking the update button, the program would try to match these numbers one by one against the numbers available in a specific column in the Inventory sheet.
(3) If the number is matched, then insert 1 in the same row under a specific column
(4) If the code is a repeat, then the value should be increased by 1 every time the number appears in the search
(5) If a number is not found, then should automatically update the number at the end of the list in the Code column and insert 1 in the relevant cell next to it.
I am attaching a sample file for your reference.
The DAILY_ORDERS_AUGUST Sheet contains the date-wise daily orders received for our products. If there is more than one order for a particular product, then the same is repeated in the list.
The VBA program would search the INVENTORY SHEET for each of these orders under SKU and if found would update "1" in the corresponding cell under ORDERS(OUT) column.
If the product is repeated in the order list, then the number would be 2 or 3 or so on.
If a SKU is not found then the SKU would be autmatically updated at the end of the list and "1' entered in the ORDERS(OUT) Column.
Would be extremely grateful if someone can please help me with coding.
Sincere Thanks in advance.
Regards
Koel
Power Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
Hi Koel,
You can try this code:
Dim InvSheet As Worksheet, Orders As Worksheet, i As Long, RowIndex As Long, ColumnIndex As Integer, OrderDay As Byte
Set InvSheet = ThisWorkbook.Worksheets("INVENTORY SHEET")
Set Orders = ThisWorkbook.Worksheets("DAILY ORDERS_AUGUST")
Dim invDict As Object: Set invDict = CreateObject("scripting.dictionary")
'read inventory
i = 3
Do
invDict.Add Key:=InvSheet.Cells(i, "C").Value, Item:=i
i = i + 1
Loop Until Len(InvSheet.Cells(i, "C").Value) = 0
'read and distribute orders
i = 2
Do
If invDict.Exists(Orders.Cells(i, "B").Value) Then
RowIndex = invDict(Orders.Cells(i, "B").Value)
OrderDay = Day(Orders.Cells(i, "A").Value)
ColumnIndex = OrderDay * 2 + 4
InvSheet.Cells(RowIndex, ColumnIndex).Value = InvSheet.Cells(RowIndex, ColumnIndex).Value + 1
End If
i = i + 1
Loop Until Len(Orders.Cells(i, "B").Value) = 0
Set InvSheet = Nothing
Set Orders = Nothing
End Sub
Just an advice:
This data structure you're using is not the best way to handle inventory. Normally, the data should be in a tabular format, and the data entry form should be separated from the reports, manually typing data in the table designed for viewing data is a bad idea, there is an old conflict between data entry and data visualization: an efficient data structure for collecting data is almost always not a proper structure for visualize the data, and a structure designed for easy visualization is usually a poor structure for manipulating data efficiently. This is the reason why data entry should be separated from reports.
In other words, it's a bad idea to eat in the toilet room, activities should be separated 🙂
New Member
August 10, 2019
Thanks Catalin,
Perhaps I could not explain properly. I have a list of alphanumeric values which would be copied from a column of an excel sheet (Say WK1:SH1) and I need to paste these values into a Text Box of a User form of a sheet in another Workbook (Say : WK2-Sh1). Then we have to add a "UPDATE" button in the userform which when clicked will check a particular column of the WK2-Sh1 one by one and if matched then will update the corresponding cell in WH2-Sh2 with 1.
There is no REPORT generation here, only updation based on certain criterion as mentioned above.
Thanks
Power Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
That's what the code does, just try it, add the code in a module then assign it to a button.
There is no report generation here, that's exactly what i said: you should enter data in a tabular structure, not in INVENTORY SHEET which is designed for visualization, not for proper data entry.
1 Guest(s)