查看VBA宏/代码,可在Excel电子表格中执行此简单匹配/部分匹配功能。
我在excel工作簿中有2张。
Sheet1包含
ColumnA =名字
ColumnB =姓氏
ColumnC =职位名称
Sheet2包含
ColumnA =名字
ColumnB =姓氏
ColumnC =职位名称
ColumnD =电子邮件
我想要宏来查看/匹配Sheet1 ColumnA,B,C和Sheet2 ColumnA,B,C 并将Sheet2 ColumnD数据放入Sheet1 columnD,各行匹配。
注意:
在进行vlookup / match / partial匹配时,数据可能区分大小写
必须做部分匹配Sheet1和Sheet2" C"各行的列
以下是附加文件样本,结果应该在运行宏后查看。
Sample and results files 我经历过这些帖子但没有找到答案。
how to get data in sheet2 from sheet1 in excel
How to copy data from sheet1 to sheet2 with a condition in Excel
merge data with partial match in r
Excel VBA - Search for value from sheet1 in sheet2 and update with adjacent value from sheet1
答案 0 :(得分:0)
您可以尝试 FOR循环来比较值:
string.replace(word, <span>{word}</span>);
答案 1 :(得分:0)
您可以使用AutoFilter()
并过滤Sheet2列A到C以及每个Sheet1行的相应值:
Option Explicit
Sub CompleteData()
Dim myRng As Range, cell As Range
With Worksheets("Sheet1")
Set myRng = .Range("A2", .cells(.Rows.Count, 1).End(xlUp)).SpecialCells(xlCellTypeConstants, xlTextValues)
End With
With Worksheets("Sheet2")
With .Range("C1", .cells(.Rows.Count, 1).End(xlUp))
For Each cell In myRng
.AutoFilter Field:=1, Criteria1:=cell.Value
.AutoFilter Field:=2, Criteria1:=cell.Offset(, 1).Value
.AutoFilter Field:=3, Criteria1:=cell.Offset(, 2).Value
If Application.WorksheetFunction.Subtotal(103, .cells) > 1 Then cell.Offset(, 3).Value = .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).cells(1, 4).Value
.Parent.AutoFilterMode = False
Next
End With
.AutoFilterMode = False
End With
End Sub