Hi, I'm working with a table which contains JIS numbers and I'm trying to match a JIS number with appropriate work orders from another table. The second table contains multiple work orders per JIS. I've already written code to verify the number of JIS in each table and then add new rows so there should be an empty row in the processed table to match the work orders being pulled in from the raw table. What I want to do is:
For each JIS number listed in raw_tbl, match to a JIS number in processed_tbl.
If processed_tbl has an empty space in the corresponding Work Order column, fill in the values on that row with the ones from raw_tbl.
If the space has been used already, find the next instance of that JIS in processed_tbl and check again, repeat until an empty work order space is found.
I originally wrote this with application.match, not sure if this is appropriate or if I should switch to a .find method. I'm including the snippet I'm working with below, can add more if necessary but trying to keep the request uncluttered as I've tried several things and I'm sure I have some unused variables and/or commented lines throughout the rest of the code. I'd also rather not use offsets as these tables and/or the report they're created from may be rearranged occasionally. The code, as written, matches the JIS appropriately but overwrites the old data on the same line it originally matched with. Any help would be appreciated.
For each JIS number listed in raw_tbl, match to a JIS number in processed_tbl.
If processed_tbl has an empty space in the corresponding Work Order column, fill in the values on that row with the ones from raw_tbl.
If the space has been used already, find the next instance of that JIS in processed_tbl and check again, repeat until an empty work order space is found.
I originally wrote this with application.match, not sure if this is appropriate or if I should switch to a .find method. I'm including the snippet I'm working with below, can add more if necessary but trying to keep the request uncluttered as I've tried several things and I'm sure I have some unused variables and/or commented lines throughout the rest of the code. I'd also rather not use offsets as these tables and/or the report they're created from may be rearranged occasionally. The code, as written, matches the JIS appropriately but overwrites the old data on the same line it originally matched with. Any help would be appreciated.
VBA Code:
For Each r In raw_tbl.ListColumns(raw_JIS_col_idx).DataBodyRange
Set rangeFind = .Find(r.Value, LookIn:=xlValues)
If Not rangeFind Is Nothing Then 'JIS found in processed table
'if "Work Order #: Work Order Number" value is empty
For lc = 1 To raw_tbl.ListColumns.Count
mc = Application.Match(raw_tbl.HeaderRowRange(, lc), processed_tbl.HeaderRowRange, 0)
If Not IsError(mc) Then
pRow = rangeFind.Row
pCol = processed_tbl.ListColumns(mc).Index
x = raw_tbl.DataBodyRange(rRow - 1, lc).Value
processed_tbl.DataBodyRange(pRow - 1, pCol).Value = x
End If
Next lc
'else
'search for the next matching rangefind
End If
Next r