Excel精英培训网

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

[已解决]请老师帮忙修改,在查询出[库存]数据后,根据[编码]匹配[记录]中的类型

[复制链接]
发表于 2016-7-9 23:16 | 显示全部楼层 |阅读模式
本帖最后由 win9 于 2016-7-9 23:20 编辑

图片说明: 2016-07-10_225253.jpg 类似效果:=VLOOKUP(库存!$B2,记录!A:E,5,0)
附件:
查询【库存】数据,匹配【记录】类型.rar (28.34 KB, 下载次数: 6)
excel精英培训的微信平台,每天都会发送excel学习教程和资料。扫一扫明天就可以收到新教程
发表于 2016-7-11 09:17 | 显示全部楼层    本楼为最佳答案   
  1. Private Sub CommandButton1_Click()
  2.     Dim d, i%
  3.     Set d = CreateObject("Scripting.Dictionary")
  4.     ListView1.ListItems.Clear '清除listview1中的内容
  5.     With Sheets("记录")
  6.         For j = 2 To .[A65536].End(xlUp).Row
  7.             If Not d.Exists(.Cells(j, 1).Value) Then
  8.                 d.Add .Cells(j, 1).Value, .Cells(j, 5).Value
  9.             End If
  10.         Next
  11.     End With
  12.    
  13.     With Sheets("库存")
  14.     For i = 2 To .[C65536].End(xlUp).Row
  15.         If InStr(1, .Cells(i, 3).Value, TextBox1.Text, vbTextCompare) Then
  16.         Set itm = ListView1.ListItems.Add() '为listview1控件里面的行添加内容
  17.             itm.Text = .Cells(i, 2) '为行标赋值
  18.             itm.SubItems(1) = .Cells(i, 3)
  19.             itm.SubItems(2) = .Cells(i, 4)
  20.             itm.SubItems(3) = .Cells(i, 5)
  21.             itm.SubItems(4) = .Cells(i, 6)
  22.             itm.SubItems(5) = d(.Cells(i, 3).Value)
  23.         End If
  24.     Next i
  25.     If ListView1.ListItems.Count = 0 Then MsgBox "未查询到相关记录!", 64, "结果"
  26.     End With

  27. End Sub
复制代码
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-4-26 04:30 , Processed in 0.152300 second(s), 9 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

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