Find matching value in table, check if specific cell in same row is empty, find next if not

dubyarly

New Member
Joined
Nov 12, 2015
Messages
44
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.

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
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,223,882
Messages
6,175,165
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top