如果将粘贴工作表 1 b 匹配到工作表 2 b,则将某些文本工作表 1 a 与工作表 2 a 匹配
我有一张工作表 1,其 A 列中有名称,而工作表 2 的 A 列中有名称。除了工作表 2 上的逗号或句点(而不是工作表 1 上的逗号或句点)外,名称大部分相同。我需要匹配一些文本和将工作表 1 的 B 列粘贴到工作表 2 的 B 列。
示例:
工作表 1
A B
Doug, Inc. $12.03
For it all, LLC $4452.03
Go for it, Inc. $235.60
Sheet 2
A B
Doug, Inc - Joe
For it all - Mike
Go for it Inc - Tom
我的代码只有在名称完全匹配(在破折号“-”之前)时才会匹配和粘贴。 我需要帮助让它只匹配一些文本,而不关心逗号或句点。
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim rng1 As Range
Set ws1 = Sheets(1)
Set ws2 = Sheets(2)
Set rng1 = ws2.Range(ws2.[a1], ws2.Cells(Rows.Count, "A").End(xlUp))
With rng1.Offset(0, 1)
.FormulaR1C1 = "=IF(RC[-1]<>"""",IF(NOT(ISERROR(MATCH(LEFT(RC[-1],FIND("" - "",RC[-1])-1),'" & ws1.Name & "'!C[-1],0))),INDEX('" & ws1.Name & "'!C,MATCH(LEFT(RC[-1],FIND("" - "",RC[-1])-1),'" & ws1.Name & "'!C[-1],0)),""""),"""")"
.Value = .Value
End With
I have a sheet1 that has names in column A and I have names in sheet 2 column A. The names are mostly the same, besides a comma or period on sheet 2 and not on sheet 1. I need to match some of the text and take sheet 1 column B and paste to sheet 2 column B.
example:
Sheet 1
A B
Doug, Inc. $12.03
For it all, LLC $4452.03
Go for it, Inc. $235.60
Sheet 2
A B
Doug, Inc - Joe
For it all - Mike
Go for it Inc - Tom
I have code that will match and paste only if the names match exact, before the dash "-".
I need help getting it to match just some of the text, not caring about the comma's or periods.
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim rng1 As Range
Set ws1 = Sheets(1)
Set ws2 = Sheets(2)
Set rng1 = ws2.Range(ws2.[a1], ws2.Cells(Rows.Count, "A").End(xlUp))
With rng1.Offset(0, 1)
.FormulaR1C1 = "=IF(RC[-1]<>"""",IF(NOT(ISERROR(MATCH(LEFT(RC[-1],FIND("" - "",RC[-1])-1),'" & ws1.Name & "'!C[-1],0))),INDEX('" & ws1.Name & "'!C,MATCH(LEFT(RC[-1],FIND("" - "",RC[-1])-1),'" & ws1.Name & "'!C[-1],0)),""""),"""")"
.Value = .Value
End With
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经重构了您的公式,
Data
VLookup
而不是Index(Match(
) 来进一步缩短公式Substitute
的替换查找范围中的,
和.
Substitues< 的
数组公式
> 工作。Substitute
返回的值是一个字符串,我已将函数包装在Value
中以转换回数字,如果不需要,请删除它。- ...
(如果存在)'
我不确定您的示例数据的一个方面
For it all - Mike
将成为For it all
。- 这不会匹配
For it all, LLC
(变成For it all LLC
)Go for it Inc - Tom< /code> 将成为
Go for it Inc
。- 这将匹配
Go for it, Inc.
(变成Go for it Inc
)Doug, Inc - Joe
将成为Doug, Inc
。此不会匹配
Doug, Inc.
(将成为 Doug Inc`)-如果您想忽略
、
和,则 。< /code> 在两个工作表中,使用
I have refactored your formula
Data
VLookup
rather thanIndex(Match(
to further shorthen the formulaSubstitute
's replace,
and.
in the lookup rangeArray formula
for theSubstitues
to work.Substitute
the returned value is a string. I've wraqpped the function in aValue
to convert back to a number, Remove this if not required.- ...
if present'
There is one aspect of your sample data that I am unsure about
For it all - Mike
will becomeFor it all
.- This won't match
For it all, LLC
(which becomesFor it all LLC
)Go for it Inc - Tom
will becomeGo for it Inc
.- This will match
Go for it, Inc.
(which becomesGo for it Inc
)Doug, Inc - Joe
will becomeDoug, Inc
.- This won't match
Doug, Inc.
(which becomes Doug Inc`)If you want to ignore
,
and.
in both sheets, use我不确定我是否理解您想要实现的目标。我不明白你的代码似乎只是清除了工作表 2 的 B 列。我不明白你为什么使用宏来设置公式。
下面的代码做了我认为你想做的事情。如果没有,我希望我的代码能给您足够的想法,以便您可以创建您想要的代码。
我猜您对 Excel Basic 不太熟悉。如果以下内容侮辱了您的知识,请抱歉。我想你宁愿被侮辱也不愿被困惑。
希望这有帮助。如果我没有充分解释自己,请回来。
I am not sure I understand what you are trying to achieve. I do not understand your code which just seems to clear column B of sheet 2. I do not understand why you are using a macro to set formula.
The code below does what I think you are trying to do. If not, I hope my code gives you enough ideas so you can create the code you seek.
I am guessing you are not that familiar with Excel Basic. Sorry if the following insults your knowledge. I assume you would rather be insulted than confused.
Hope this helps. Come back if I have not explained myself adequately.