Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 8971|回复: 17

[已解决]求VBA代码代替VLOOKUP或者用VBA调用VLOOKUP。

[复制链接]
发表于 2012-8-27 15:48 | 显示全部楼层 |阅读模式
实际的工作,可能表格中会有几十万条不等,所以,原来是用VLOOKUP往下拉,但是这个很费时间,前面的型号是用循环语句跑出来的,希望这个也能用VBA来代替下,哪位高手帮下忙。我是初学阶段,能看懂个大概,但是自己写不出。
最佳答案
2012-8-27 18:02
这种表格,先跑单元格,用字典要麻烦一点,跑单元格容易点,写代码费神
  1. Sub test()
  2.     Dim LastRow, i, sht As Worksheet
  3.     Set sht = Sheets("Sheet1")
  4.     LastRow = sht.Range("A" & Rows.Count).End(xlUp).Row
  5.     With Sheets("选型表")
  6.     For i = 3 To LastRow
  7.         If sht.Cells(i, "A") = "" Then sht.Cells(i, "J") = "" Else sht.Cells(i, "J") = Application.WorksheetFunction.VLookup(sht.Cells(i, "A"), .Range("A2:D3"), 2, 0)
  8.         If sht.Cells(i, "B") = "" Then sht.Cells(i, "K") = "" Else sht.Cells(i, "K") = Application.WorksheetFunction.VLookup(sht.Cells(i, "B"), .Range("A6:C9"), 2, 0)
  9.         If sht.Cells(i, "C") = "" Then sht.Cells(i, "L") = "" Else sht.Cells(i, "L") = Application.WorksheetFunction.VLookup(sht.Cells(i, "C"), .Range("A11:D12"), 2, 0)
  10.         If sht.Cells(i, "D") = "" Then sht.Cells(i, "M") = "" Else sht.Cells(i, "M") = Application.WorksheetFunction.VLookup(sht.Cells(i, "D"), .Range("A15:B17"), 2, 0)
  11.         If sht.Cells(i, "E") = "" Then sht.Cells(i, "N") = "" Else sht.Cells(i, "N") = Application.WorksheetFunction.VLookup(sht.Cells(i, "E"), .Range("A19:D22"), 2, 0)
  12.         If sht.Cells(i, "F") = "" Then sht.Cells(i, "O") = "" Else sht.Cells(i, "O") = Application.WorksheetFunction.VLookup(sht.Cells(i, "F"), .Range("A24:D26"), 2, 0)
  13.         If sht.Cells(i, "G") = "" Then sht.Cells(i, "P") = "" Else sht.Cells(i, "P") = Application.WorksheetFunction.VLookup(sht.Cells(i, "G"), .Range("A28:D29"), 2, 0)
  14.         If sht.Cells(i, "H") = "" Then sht.Cells(i, "Q") = "" Else sht.Cells(i, "Q") = Application.WorksheetFunction.VLookup(sht.Cells(i, "H"), .Range("A31:D31"), 2, 0)
  15.     Next
  16.     End With
  17. End Sub
复制代码

求VBA代替VLOOKUP.zip

15.55 KB, 下载次数: 88

发表于 2012-8-27 16:03 | 显示全部楼层
回复

使用道具 举报

 楼主| 发表于 2012-8-27 16:14 | 显示全部楼层
能不能帮忙,写下我那一段啊。上面那个连接好复杂啊。谢谢
回复

使用道具 举报

 楼主| 发表于 2012-8-27 16:51 | 显示全部楼层
老糊涂 发表于 2012-8-27 16:03
http://www.excelpx.com/forum.php?mod=viewthread&tid=254587&reltid=258162&pre_thread_id=0&pre_pos=1&e ...

您好,能不能帮我写下,我的那个啊,那个连接贴我看不明白,要是能帮我写一个我的那个附件的,我就能看得明白了。而且还可以应用了。麻烦您了
回复

使用道具 举报

发表于 2012-8-27 17:18 | 显示全部楼层
中世纪书生 发表于 2012-8-27 16:51
您好,能不能帮我写下,我的那个啊,那个连接贴我看不明白,要是能帮我写一个我的那个附件的,我就能看得 ...

我2003版,文件打不开
回复

使用道具 举报

发表于 2012-8-27 17:28 | 显示全部楼层
选型做的很不好,表格设计不合理
回复

使用道具 举报

 楼主| 发表于 2012-8-27 17:33 | 显示全部楼层
5201314 发表于 2012-8-27 17:28
选型做的很不好,表格设计不合理

能否帮我写下就是sheet1里M到~W列为中文注解部分。如何能用VBA实现这样的功能。谢谢
回复

使用道具 举报

 楼主| 发表于 2012-8-27 17:34 | 显示全部楼层
5201314 发表于 2012-8-27 17:28
选型做的很不好,表格设计不合理

表格形式,是公司要求的标准文件。我不能更改。
回复

使用道具 举报

发表于 2012-8-27 17:36 | 显示全部楼层
选型表也是公司做的吗?那个你都不能设计?
回复

使用道具 举报

 楼主| 发表于 2012-8-27 17:47 | 显示全部楼层
5201314 发表于 2012-8-27 17:36
选型表也是公司做的吗?那个你都不能设计?

选型表是罗斯蒙特公司的东西,我们是做网站的,需要用程序跑出他的所有型号,和中文注解,选型表是更不可更改的了。谢谢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-30 15:05 , Processed in 0.370527 second(s), 14 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表