0

我有一个 Excel 表,每行都有地址列表

IE

COLUMN A
My Company 123 Big Street Ashgrove QLD 4111
A Better Compant PO Box 123 Sandgate QLD 4111

我有另一张表,其中每个 QLD 郊区按字母顺序在一个名为的命名范围内rSuburbs

IE

Ashgrove
BBBB
CCC
Sandgate
Zilmere

我可以写什么公式来找到最接近的匹配并将其转储出来,即像这样:

COLUMN A                                          COLUMN B
My Company 123 Big Street Ashgrove QLD 4111       Ashgrove
A Better Compant PO Box 123 Sandgate QLD 4111     Sandgate
4

3 回答 3

2

在B2中尝试这个公式复制下来

=LOOKUP(2^15,SEARCH(" "&rSuburbs&" "," "&A2&" "),rSuburbs)

使用 " "& 确保您不会得到部分匹配

于 2013-09-26T11:29:29.390 回答
1

假设您的郊区列表在 K2:6 列中,标题为 K1 中的郊区:

{=INDEX(K:K,LARGE(IFERROR(FIND($K$2:$K$6,A2)*0+ROW(A$2:A$6),0),1))}

数组公式必须用ctrl+ shift+确认enter——不要试图手动输入花括号!

这将返回所需的输出。

基本上,确定每个列表是否在 A 列的文本中,如果是则返回郊区的行号,如果不是则返回零,然后取你得到的最大索引的郊区。

于 2013-09-26T08:44:12.650 回答
0

如果您对 vba 解决方案感兴趣,这将在 B 列中打印郊区名称,修改以匹配您的工作簿。

Option Explicit
Sub splitlr()
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim s As String, str As String
    Dim i As Integer, j As Integer, k As Integer, l As Integer
    Dim lr As Long
    Dim a As Long

    Set wb = ThisWorkbook
    Set ws = wb.Sheets("Sheet1")
    lr = ws.Range("A" & Rows.Count).End(xlUp).Row + 1
    With ws
        a = 1
        Do Until a = lr
            s = .Range("A" & a).Text
            i = Len(s)
            j = InStrRev(s, " ") - 1
            k = InStrRev(s, " ", j) - 1
            l = InStrRev(s, " ", k)
            str = Mid(s, l, (i - k))
            .Range("B" & a).Value = str
            a = a + 1
        Loop
    End With
End Sub
于 2013-09-26T08:52:54.343 回答