问个VBA的问题
有两列数,求列中值相同的项,并返回。假设第一列和第二列中都有9,最后结果也返回9。用什么函数公式?
1288
1148
697
755
99
213
9614
482
465
894
846
[解决办法]
在你的 Excel文档中插入一个标准模块,粘贴下面的代码,运行试这个 Sub 试一下:
Option ExplicitSub Test() Dim a$(), i&, k&, p&, txt$ Dim objSht As Worksheet Set objSht = Sheets("Sheet1") '数据在 Sheet1 中 k = 2 '数据起始行为 2 ReDim a(WorksheetFunction.CountA(objSht.Range("A:A")) - 1) p = -1 i = k: Do txt = objSht.Cells(i, 2) If (txt = "") Then Exit Do p = p + 1: a(p) = txt i = i + 1 Loop i = k: Do txt = objSht.Cells(i, 1) If (txt = "") Then Exit Do For k = 0 To p If (txt = a(k)) Then objSht.Cells(i, 3) = txt Exit For End If Next i = i + 1 LoopEnd Sub