我想请求如何从表1中获取数据并从表2列A中获取数据并查看表1列B中的结果,查看或搜索前3个字符/数字。我在Sheet1 col A中有超过15000个数据,在表2中有大约100个选择(类型)。如何使用宏...?
Example
Sheet1 on sheet 2
Number (Col A) | Type (column B) Col A | Col B (Type)
A112XXX2 Engine1 A112XXX2 Engine1
B112AA12 ?? B333QWE1 Engine2
B222VXX2 ?? C000XXX2 Engine3
B333QWE1 ?? Z312VVV9 Engine10
.
.
基本上在Sheet1列A中使用前4个字符/数字(比如A112作为我的标准),在Sheet2列A上找到数据,然后数据将出现在Sheet1列-B(类型)
谢谢,谢谢你的帮助。 wezzer
答案 0 :(得分:0)
因此,如果您想使用VBA,那么这些就是这些内容:
Sub Find()
Dim sht1 As Worksheet, sht2 As Worksheet
Dim lRow As Long, lRow2 As Long
Set sht = ThisWorkbook.Worksheets("Sheet1")
Set sht2 = ThisWorkbook.Worksheets("Sheet2")
lRow = sht.Cells(sht.Rows.Count, 1).End(xlUp).Row
lRow2 = sht2.Cells(sht2.Rows.Count, 1).End(xlUp).Row
For j = 1 To lRow
For i = 1 To lRow2
If Left(sht.Cells(j, 1).Value, 4) = Left(sht2.Cells(i, 1).Value, 4) Then
sht.Cells(j, 2).Value = sht2.Cells(i, 2).Value
Exit For
End If
Next i
Next j
End Sub
正如Peh所说,你可以用一个公式来做,但考虑到数据集的数量,这可能会导致糟糕的表现。