• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Using VBA to search a list of Alphanumeric numbers in a bigger list of Alphanumeric numbers and then enter a numeric value in the cell corresponding to it|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Using VBA to search a list of Alphanumeric numbers in a bigger list of Alphanumeric numbers and then enter a numeric value in the cell corresponding to it|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosUsing VBA to search a list of Alpha…
sp_PrintTopic sp_TopicIcon
Using VBA to search a list of Alphanumeric numbers in a bigger list of Alphanumeric numbers and then enter a numeric value in the cell corresponding to it
Avatar
Koel Sg

New Member
Members
Level 0
Forum Posts: 2
Member Since:
August 10, 2019
sp_UserOfflineSmall Offline
1
August 10, 2019 - 1:39 am
sp_Permalink sp_Print

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

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
August 13, 2019 - 3:08 pm
sp_Permalink sp_Print sp_EditHistory

Hi Koel,

You can try this code:

Sub DistributeSKU()
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 🙂

Avatar
Koel Sg

New Member
Members
Level 0
Forum Posts: 2
Member Since:
August 10, 2019
sp_UserOfflineSmall Offline
3
August 18, 2019 - 1:10 am
sp_Permalink sp_Print

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

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
August 18, 2019 - 3:14 am
sp_Permalink sp_Print

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.

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
5
August 18, 2019 - 3:26 am
sp_Permalink sp_Print

Updated the code to add new rows in inventory, added a button also to make it easy for you.

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Alexandra Radu
Guest(s) 10
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 871
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Raj Mattoo
Mark Luke
terimeri dooriyan
Jack Aston
AndyC
Denise Lloyd
michael serna
mashal sana
Tiffany Kang
Leah Gillmore
Forum Stats:
Groups: 3
Forums: 24
Topics: 6219
Posts: 27276

 

Member Stats:
Guest Posters: 49
Members: 31903
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.