我有一张Excel表格,每行都有一个地址列表
即
COLUMN A
My Company 123 Big Street Ashgrove QLD 4111
A Better Compant PO Box 123 Sandgate QLD 4111
我在其中的每个QLD郊区都有一张名为rSuburbs
即
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
答案 0 :(得分: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 + 输入确认数组公式 - 不要尝试手动输入波浪形大括号!功能
这将返回所需的输出。
基本上,弄清楚每个列表是否在A列的文本中,如果是,则返回郊区的行号,如果不是,则返回零,并获取您获得的最大索引的郊区。
答案 1 :(得分:1)
在B2中复制此公式
=LOOKUP(2^15,SEARCH(" "&rSuburbs&" "," "&A2&" "),rSuburbs)
使用“”&确保您不会获得部分匹配
答案 2 :(得分: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