选择工作表之间的数据以写入Vlookup功能

时间:2012-02-10 12:18:18

标签: excel vba

我在表单(销售数据)表格中有数据单元格B7:B207,我正在尝试编写一个vba代码,用于使用数据在工作表(Salesmen Info)中生成Vlookup功能。但是我没能生成VBA代码。请告知我如何在(推销员信息)中生成VLookup。

2 个答案:

答案 0 :(得分:1)

您可以使用标准功能{/ 3}} 在VBA之外

=vlookup(A1,"Sales Data"!$B$7:$B$207,1,false)

如果您的VBA失败,请确保每次调用时都在引号中引用“销售数据”表。 您目前的VBA代码是什么

另外,为什么要尝试vlookup一列(B)。您需要您的范围至少为2列,以便它可以在B中找到数据并从C

返回数据

答案 1 :(得分:0)

我喜欢applciation.vlookup

arr = application.vlookup(A1,"Sales Data"!$B$7:$B$207,1,false)

然后,这应该工作(输入没有excel方便所以它可能不会!):

for i = 0 to ubound(arr,0)
    for j = 0 to ubound(arr,1)
        debug.print arr(i,j)
    next
next

(按Ctrl + J查看即时窗口并查看输出)

或者你想把它放在一张纸上?

dim rng as range
set rng = range("A1")

for i = 0 to ubound(arr,0)
    for j = 0 to ubound(arr,1)
        rng.offset(i,j).value = arr(i,j)
    next
next