I need to find a row based on multiple criteria, with a catch.

rcrumbliss

New Member
Joined
Jan 30, 2024
Messages
11
Office Version
  1. 365
Platform
  1. Windows
I have been working on this for a couple days and it is frustrating. I have found many Posts about simple matching of criteria, but I cant figure how to make any of those methods work for my situation.

I have 2 worksheets in my book. The first worksheet is a master list of addresses. The address format for these is like this...
LoopSequenceLow AddressHigh AddressPrefixStreet NameSuffix
10001500WAnywhereSt

The second worksheet is a list of specific addresses formatted like this...
LoopSequenceStreet NumberPrefixStreet NameSuffix Consignee


The problem I have is I need to look up the information in Sheet 2, find the specific row in Sheet 1 which pertains to the address in each row. So I need to look at the Street name, and then check if the street number falls within the Low/High range for that street. I have over 25000 address ranges to look through. The current method I have been using is very slow, taking 2 hours and more to look up the 1000 addresses in Sheet 2. I need to speed this up, but I am not finding a way to do it that works.

Can someone please help. Below is the code I am currently using. I cannot include the source data I am using due to privacy issues.

VBA Code:
Public Sub ProcessFinal()

Dim OFile As Worksheet: Set OFile = Sheets("OUTPUT FILE")  'output file
Dim EC As Worksheet:    Set EC = Sheets("ENTIRE CENTER")         'Entire Center
Dim IC As Worksheet     'Imported Closures
Dim CD As Worksheet     'Copy Data from PFT
Dim i As Integer        'Counter
Dim DupRow As Integer   'to save row of duplicates
Dim LoopNum, SeqNum As String
Dim FoundRow As Integer


For i = 2 To [match(2,1/(a:a<>""))]
    If OFile.Range("D" & i).Value = "@@" Then LoopNum = 0 Else LoopNum = OFile.Range("D" & i).Value
    If OFile.Range("E" & i).Value = "@@" Then SeqNum = 0 Else SeqNum = OFile.Range("E" & i).Value
    FoundRow = CheckAdd(OFile.Range("G" & i), OFile.Range("H" & i), OFile.Range("I" & i), OFile.Range("J" & i), OFile.Range("K" & i))
    
        If OFile.Range("D" & i) = EC.Range("C" & FoundRow) And OFile.Range("E" & i) = EC.Range("D" & FoundRow) Then
            'Loop and Sequence are a match move on to next step
        Else
            'Loop and Sequence do not match, add new Loop/Seq to row "O" and update exclude
            OFile.Range("N" & i) = "Yes"
            OFile.Range("O" & i) = "Relooped, new Loop/Seq is : " & EC.Range("C" & FoundRow) & "/" & EC.Range("D" & FoundRow)
            OFile.Range("P" & i) = "Verify New L/S in CLO if needed"
        End If
            
Next
    


End Sub


Public Function CheckAdd(StrNum As String, Pfx As String, Street As String, Sfx As String, StrType As String) As Integer

Dim OFile As Worksheet: Set OFile = Sheets("OUTPUT FILE")  'output file
Dim EC As Worksheet:    Set EC = Sheets("ENTIRE CENTER")         'Entire Center
Dim IC As Worksheet     'Imported Closures
Dim CD As Worksheet     'Copy Data from PFT
Dim rng As Range
Dim StreetNum As Long

StreetNum = CLng(StrNum)
    On Error Resume Next
    Err.Number = 0
    Set rng = EC.Range("J:J").Find(What:=Street, LookIn:=xlValues)
    rng.Find What:=Street, LookIn:=xlValues
    myRow = rng.Row
        
    Do While myRow < EC.[match(2,1/(a:a<>""))]
    If EC.Range("F" & myRow) <= StreetNum And EC.Range("G" & myRow) >= StreetNum Then
        'Call MsgBox("Match Found for" & StrNum & " " & Street & "at row: " & myRow & " of the Entire Center")
        CheckAdd = myRow
        Exit Function
    Else
        'MsgBox "No"
    End If
    Set rng = EC.Range("J:J").FindNext(rng)
    myRow = rng.Row
    Loop
    
End Function
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Do you need to use VBA?
Here is a formula possibility:

Book1
ABCDEFGHIJ
1LoopSequenceLow AddressHigh AddressPrefixStreet NameSuffix
210001500WAnywhereSt
3
4The second worksheet is a list of specific addresses formatted like this...
5LoopSequenceStreet NumberPrefixStreet NameSuffixConsigneeIN:
6900WAnywhereStNo
71000WAnywhereStYes
81250WAnywhereStYes
91500WAnywhereStYes
101750WAnywhereStNo
11
Sheet2
Cell Formulas
RangeFormula
I6:I10I6=IF((C6>=$C$2)*(C6<=$D$2)*(D6=$E$2)*(E6=$F$2)*(F6=$G$2),"Yes","No")
 
Upvote 0
Do you need to use VBA?
Here is a formula possibility:

Book1
ABCDEFGHIJ
1LoopSequenceLow AddressHigh AddressPrefixStreet NameSuffix
210001500WAnywhereSt
3
4The second worksheet is a list of specific addresses formatted like this...
5LoopSequenceStreet NumberPrefixStreet NameSuffixConsigneeIN:
6900WAnywhereStNo
71000WAnywhereStYes
81250WAnywhereStYes
91500WAnywhereStYes
101750WAnywhereStNo
11
Sheet2
Cell Formulas
RangeFormula
I6:I10I6=IF((C6>=$C$2)*(C6<=$D$2)*(D6=$E$2)*(E6=$F$2)*(F6=$G$2),"Yes","No")


That would only work if there was only one street range to search, however I have 25000 street ranges, with over 500,000 possible single point addresses within those 25000 ranges.

What I need to do is get the specific row from Sheet 1 that contains the address in Sheet 2 so that I can compare the data, make updates to Sheet 2. Sheet 2's layout cannot change. I have to send that sheet back up to corporate so they can integrate it into their master sheet. Currently we are doing this work by hand, one address at a time, and I am building this to streamline our process and cut down on hours spent doing this work.
 
Upvote 0
No, you gave only 1 row to check.
Give more samples and we'll see what can happen.

Book1
ABCDEFGHI
1LoopSequenceLow AddressHigh AddressPrefixStreet NameSuffix
210001500WAnywhereSt
34005000EParkAve
425003000Boardwalk
5
6
7
8
9
10
11
12The second worksheet is a list of specific addresses formatted like this...
13LoopSequenceStreet NumberPrefixStreet NameSuffixConsigneeIN:
14900WAnywhereStNo
151000WAnywhereStYes
161250WAnywhereStYes
171500WAnywhereStYes
181750WAnywhereStNo
19600WParkAveNo
20600EParkAveYes
214500WParkAveNo
224000EParkStNo
233000BoardwalkYes
Sheet2
Cell Formulas
RangeFormula
I14:I23I14=IF(SUM((C14>=$C$2:$C$4)*(C14<=$D$2:$D$4)*(D14=$E$2:$E$4)*(E14=$F$2:$F$4)*(F14=$G$2:$G$4))>0,"Yes","No")
 
Last edited:
Upvote 0
Here is a snip of data. The first table is from the master list, which contains over 25000 address ranges. The second is a small snip (sensitive information deleted) from Sheet 2, which is individual addresses. I need to use the data from Sheet 2, to find the row in sheet 1 which contains the correct range of Low/High addresses, and return the row from Sheet 1.


LoopSequenceUnitPrimaryLowPrimaryHighParityPfxStreetNameStreetTypeSfxCityStatePostalCodeHiLowMap
1​
5​
101​
5699​
5400​
S178THSTTUKWILAWA
98188​
XX
1​
10​
101​
17800​
17899​
54THPLSSEATACWA
98188​
X
1​
15​
101​
5699​
4800​
S178THSTSEATACWA
98188​
XX
1​
20​
101​
17799​
17700​
50THCTSSEATACWA
98188​
XX
1​
25​
101​
17598​
17500​
EMILITARYRDSSEATACWA
98188​
XX
1​
30​
101​
4700​
4729​
S175THSTSEATACWA
98188​
X
1​
35​
101​
17400​
17499​
47THLNSSEATACWA
98188​
X
1​
40​
101​
4730​
4799​
S175THSTSEATACWA
98188​
X
1​
40​
101​
4800​
4899​
S175THSTSEATACWA
98188​
X
1​
45​
101​
5100​
5199​
S175THSTSEATACWA
98188​
X
1​
50​
101​
17398​
17300​
EMILITARYRDSSEATACWA
98188​
XX
1​
55​
101​
17298​
17200​
EMILITARYRDSSEATACWA
98188​
XX
1​
60​
101​
4460​
4499​
S173RDSTSEATACWA
98188​
X
1​
65​
101​
4700​
4899​
S173RDSTSEATACWA
98188​
X
1​
70​
101​
17200​
17399​
47THAVESSEATACWA
98188​
X
1​
75​
101​
4400​
4699​
S172NDPLSEATACWA
98188​
X
1​
80​
101​
4700​
4799​
S172NDPLSEATACWA
98188​
X
1​
85​
101​
4800​
4899​
S172NDPLSEATACWA
98188​
X
1​
90​
101​
17399​
17300​
51STAVESSEATACWA
98188​
XX
1​
95​
101​
5100​
5199​
S173RDLNSEATACWA
98188​
X
1​
100​
101​
5100​
5199​
S172NDPLSEATACWA
98188​
X
1​
105​
101​
17299​
17200​
51STAVESSEATACWA
98188​
XX
SHEET 2
SourceAddressPostalLoopSeqConsigneeStreetNumPreStreetSfxStreetTypeSuiteConsignee2
98188@@@@18205@@ANDOVERW
98032@@@@216WGOWE@@
9814801120115400@@1STS
98188027554755S173RDST
 
Upvote 0
What do the @@ mean? And are you looking only for street number differences? Not for discrepancies in Street Types or misspelling of street names? If not, I see no matches in your data to test with. How much matching are you seeking. Is parity really a street direction? you have a lot going on here. I do not envy you.
 
Last edited:
Upvote 0
What do the @@ mean? And are you looking only for street number differences? Not for discrepancies in Street Types or misspelling of street names? If not, I see no matches in your data to test with. How much matching are you seeking. Is parity really a street direction? you have a lot going on here. I do not envy you.
For what I am doing here, most of the data can be ignored. The @@ is what the system does when it does not find data in the back end. I am not looking for street name discrepancies, there should not be any in the data sets, since they are coming from the USPS. I did include one data point in my set, the 173rd st.

I need to take each line from the bottom set of data, and find the row in the top set of data which it would fall within. Basically, what I am currently doing is using a Do/While loop with .find to compare street names, then checking to see if the street number falls within the low/high range on each row of data, and stopping when it is found. But this is very very very slow. I am looking for a way to do it faster.
 
Upvote 0
OKay, try this:
It is matching Zip code, street name, and looking for the top and bottom street numbers. It will only give you the first matching record.
(if you want to return the row from the data, use the 'rowmatch' value in the last expression as the target row of an INDEX function.


Book1
ABCDEFGHIJKLMNOP
1LoopSequenceUnitPrimaryLowPrimaryHighParityPfxStreetNameStreetTypeSfxCityStatePostalCodeHiLowMap
21510156995400S178THSTTUKWILAWA98188XX
3110101178001789954THPLSSEATACWA98188X
411510156994800S178THSTSEATACWA98188XX
5120101177991770050THCTSSEATACWA98188XX
61251011759817500EMILITARYRDSSEATACWA98188XX
713010147004729S175THSTSEATACWA98188X
8135101174001749947THLNSSEATACWA98188X
914010147304799S175THSTSEATACWA98188X
1014010148004899S175THSTSEATACWA98188X
1114510151005199S175THSTSEATACWA98188X
121501011739817300EMILITARYRDSSEATACWA98188XX
131551011729817200EMILITARYRDSSEATACWA98188XX
1416010144604499S173RDSTSEATACWA98188X
1516510147004899S173RDSTSEATACWA98188X
16170101172001739947THAVESSEATACWA98188X
1717510144004699S172NDPLSEATACWA98188X
1818010147004799S172NDPLSEATACWA98188X
1918510148004899S172NDPLSEATACWA98188X
20190101173991730051STAVESSEATACWA98188XX
2119510151005199S173RDLNSEATACWA98188X
22110010151005199S172NDPLSEATACWA98188X
231105101172991720051STAVESSEATACWA98188XX
241
25SHEET 2
26SourceAddressPostalLoopSeqConsigneeStreetNumPreStreetSfxStreetTypeSuiteConsignee2
2798188@@@@18205@@ANDOVERWno match
2898032@@@@216WGOWE@@no match
29981481120115400@@1STSno match
309818827554755S173RDSTmatch at row 14
31981884755172NDmatch at row 17
Sheet1
Cell Formulas
RangeFormula
P27:P31P27=LET(lkzip,$C27,zips,$M$2:$M$23,lkadd,$G27,lowadds,$D$2:$D$23,highadds,$E$2:$E$23,lkname,$I27,stnames,$H$2:$H$23,nmrows,COUNT(lowadds),rowmatch,SUM((lkzip=zips)*(lkadd>=lowadds)*(lkadd<=highadds)*(lkname=stnames)*(SEQUENCE(nmrows))),IF(rowmatch=0,"no match","match at row " & rowmatch))
 
Upvote 0
OKay, try this:
It is matching Zip code, street name, and looking for the top and bottom street numbers. It will only give you the first matching record.
(if you want to return the row from the data, use the 'rowmatch' value in the last expression as the target row of an INDEX function.


Book1
ABCDEFGHIJKLMNOP
1LoopSequenceUnitPrimaryLowPrimaryHighParityPfxStreetNameStreetTypeSfxCityStatePostalCodeHiLowMap
21510156995400S178THSTTUKWILAWA98188XX
3110101178001789954THPLSSEATACWA98188X
411510156994800S178THSTSEATACWA98188XX
5120101177991770050THCTSSEATACWA98188XX
61251011759817500EMILITARYRDSSEATACWA98188XX
713010147004729S175THSTSEATACWA98188X
8135101174001749947THLNSSEATACWA98188X
914010147304799S175THSTSEATACWA98188X
1014010148004899S175THSTSEATACWA98188X
1114510151005199S175THSTSEATACWA98188X
121501011739817300EMILITARYRDSSEATACWA98188XX
131551011729817200EMILITARYRDSSEATACWA98188XX
1416010144604499S173RDSTSEATACWA98188X
1516510147004899S173RDSTSEATACWA98188X
16170101172001739947THAVESSEATACWA98188X
1717510144004699S172NDPLSEATACWA98188X
1818010147004799S172NDPLSEATACWA98188X
1918510148004899S172NDPLSEATACWA98188X
20190101173991730051STAVESSEATACWA98188XX
2119510151005199S173RDLNSEATACWA98188X
22110010151005199S172NDPLSEATACWA98188X
231105101172991720051STAVESSEATACWA98188XX
241
25SHEET 2
26SourceAddressPostalLoopSeqConsigneeStreetNumPreStreetSfxStreetTypeSuiteConsignee2
2798188@@@@18205@@ANDOVERWno match
2898032@@@@216WGOWE@@no match
29981481120115400@@1STSno match
309818827554755S173RDSTmatch at row 14
31981884755172NDmatch at row 17
Sheet1
Cell Formulas
RangeFormula
P27:P31P27=LET(lkzip,$C27,zips,$M$2:$M$23,lkadd,$G27,lowadds,$D$2:$D$23,highadds,$E$2:$E$23,lkname,$I27,stnames,$H$2:$H$23,nmrows,COUNT(lowadds),rowmatch,SUM((lkzip=zips)*(lkadd>=lowadds)*(lkadd<=highadds)*(lkname=stnames)*(SEQUENCE(nmrows))),IF(rowmatch=0,"no match","match at row " & rowmatch))


Ok, the problem I am having is that the 2 tables are on different sheets, and the LET function is not recognizing the range from the 2nd Sheet.

Excel Formula:
=LET(StrtNam,$I2,StrSrch,'ENTIRE CENTER'!$J$2:$J$29999,SPAdd,'ENTIRE CENTER'!$F$2:$F$29999,MatchingRow, SUM((StrtNam = StrSrch)*(StrtNum = SPAdd)*(SEQUENCE(SPAdd)))],[IF(MatchingRow = 0, "No Match",MatchingRow)])

All I get is a #NAME? return on every line. Can you see what the problem is?

I appreciate the help you are giving me here. This Let function is completely new to me, and I see the great potential in it. I just need to get it figured out.
 
Upvote 0
your probably getting the name problem because of the 2 different sheets issue.

Let just allows you to create temporary names inside the formula to 1. Make understanding the formula better, and 2. shorten/reduce complexity in formulas.

in the Let statement change the references by adding the other sheet name (I think it is sheet1) to the names that define ranges on sheet 1:
=LET(
lkzip,$C27,
zips,Sheet1!$M$2:$M$23,
lkadd,$G27,
lowadds,Sheet1!$D$2:$D$23,
highadds,Sheet1!$E$2:$E$23,
lkname,$I27,
stnamesSheet1!$H$2:$H$23,
nmrows,COUNT(lowadds),
rowmatch,SUM((lkzip=zips)*(lkadd>=lowadds)*(lkadd<=highadds)*(lkname=stnames)*(SEQUENCE(nmrows))),IF(rowmatch=0,"no match","match at row " & rowmatch))

if you still get the #NAME error then check your excel version and refresh. It is only in Excel 365 (which you say you have), Web, and 2021. The LET function has been around for a while.
 
Upvote 0

Forum statistics

Threads
1,223,853
Messages
6,175,013
Members
452,600
Latest member
nicoCrous75

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