Find in string with Excel and VBA?
-
I have a spreadsheet with a few worksheets in it, one being Product Inventory and one being Material Inventory... I am trying to figure out how I can have another worksheet to where I can look up a product code, pull the description out of Product Inventory, and extract materials needed from Material Inventory. I know how to do this in other languages, but I'm extremely limited to just Excel and I don't know how to go about it. Say I have Product Lookup:$B$2 = "ps26k417", which I already have pulling info from Product Inventory which pulls the item description, Garden Gate Indigo/Linen Natural 26x26 KE Fiber Pillow* But now I need to figure out how to pull from Material Inventory.. From that product description, I need to pull two rows out of the Material Inventory sheet.. I need a way to extract info based on the description, in this example I need the row for 417 Garden Gate Indigo/Linen and the row for 554 Linen Natural/S Backed Is it even worth going this in-depth in an Excel macro?
-
Answer:
If each result from the ProductInventory sheet translates into exactly two entries on the MaterialInventory sheet, the simplest option would be to use two VLOOKUPS formulae. If you'd like to go down the VBA route, you'll probably need code like the following: Public Sub SearchForMaterial(materials() As String) Dim N As Long Dim materialsList As Range Set materialsList = ' Set to the relevant range Dim cell As Range Dim output(UBound(materials) - LBound(materials)) As String Dim outputCount As Long For N = LBound(materials) To UBound(materials) For Each cell In materialsList.Cells If cell.Value = materialsList(N) Then output(outputCount) = cell.Offset(ColumnOffset:= ??) End If Next cell Next N End Sub This code isn't particularly efficient. You say that you have experience in other languages, so hopefully this should be enough to get you started.
N. Lucas at Stack Overflow Visit the source
Other answers
Depending on what else you need to do, I would make a properly structured Access database for that. You need 3 tables: Products, Materials and BOM (Bill of materials). BOM will have 3 fields: ProductId, MaterialId, Quantity. With just that, and a simple Parameter Query, you can solve your problem.
iDevlop
I gave up trying to figure this out with just Excel and VBA. I made a PHP script that converted all the columns I needed in the Products and Materials worksheets, threw all that into a MySQL database, pulled it all out as CSV and made a new spreadsheet.
N. Lucas
Does the products table have a unique ID? Does the Materials table have a foreign key related to the products table? If not...Why not? Would make things a lot easier and faster than searching with text values. Check out this http://support.microsoft.com/kb/257819 for using SQL within excel. Should be easy if you have Unique IDs.
Patrick
Related Q & A:
- How To Select Odd Numbers In Excel?Best solution by Yahoo! Answers
- How To Excel Additional Mathematics?Best solution by Yahoo! Answers
- is it possible to make comment appear faster in excel?Best solution by Super User
- How to see if one string contains another string?Best solution by Stack Overflow
- How to covert csv file to excel and back excel file to csv in python?Best solution by completecampaigns.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.