如何用vba实现在表2的A2中输入表1的A列中的品种代码,表1满足条件的行的数据自动提取到表2的对应位置。

表2
品种代码 品名 价格
201201013 A1013 253.00
订户 订户数量 金额
订户1 439
订户2 665
订户3 515
订户4 461
订户5 254
订户6 358
订户7 328
订户8 696
订户9 461
订户10 388
订户11 390
订户12 535
订户13 690
订户14 664
订户15 779
汇总 7623
感谢你的回答。问题是需要vba代码实现,不想用VLOOKUP函数,以避免因操作不当改动公式出现问题,

第1个回答  2012-04-19
用函数就可以解决
B2的公式:
=VLOOKUP($A2,表1!$A$2:$S$10,COLUMN())
其他的可向右填充,然后向下填充

'VBA:请将下列加于表2的 Worksheet_Change事件中
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 Then
Dim x%, y%
y = 2
While Not IsNull(Sheets("表1").Cells(y, 1))
x = 2
If Sheets("表1").Cells(y, 1).Value = Target.Value Then
While Not IsNull(Sheets("表1").Cells(y, x))
Sheets("表2").Cells(Target.Row, x).Value = Sheets("表1").Cells(y, x).Value
x = x + 1
Wend
End If
y = y + 1
Wend
End If
End Sub