|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub Vlookup()
- '--------------------------
- ' 定义变量
- Dim i%, r%, L, S
- Dim sh1 As Worksheet
- Dim sh2 As Worksheet
- Dim Sh1ColList As String
- Dim Sh2ColList As String
- Dim X As Long
- '----------------------------
- Application.ScreenUpdating = False
- On Error Resume Next
- '从“列表”工作表中取数的列次
- Sh1ColList = "4,5,6,7,8,9,10,16,17,20,21,22,23"
- '写到“筛选”工作表的对应列次
- Sh2ColList = "17,18,19,20,21,22,23,24,25,26,27,28,29"
- Set sh1 = ThisWorkbook.Sheets("列表")
- Set sh2 = ThisWorkbook.Sheets("筛选")
- r = sh1.Range("A65536").End(xlUp).Row '列表已使用行数
- i = sh2.Range("A65536").End(xlUp).Row '筛选已使用行数
- ' 将 列表 工作表的数据导入数组
- With sh1
- MaxCol = .Cells(1, .Columns.Count).End(xlToLeft).Column '第1行最后一列
- MaxRow = .Cells(.Rows.Count, 1).End(xlUp).Row '第1列最后一行
- sh1arr = .Range(.Cells(1, 1), .Cells(MaxRow, MaxCol)).Value
- End With
- ' 整理 筛选 工作表,删除部分数据
- sh2.Range("Q3:AC" & i).ClearContents
- sh2.[Q3:AC3] = Split("最新,涨幅,换手,量比,DDX,DDY,DDZ,BBD,单比,特差,大差,中差,小差", ",")
- ' 将 筛选 工作表的数据导入数组
- With sh2
- MaxCol = .Cells(3, .Columns.Count).End(xlToLeft).Column '第1行最后一列
- MaxRow = .Cells(.Rows.Count, 1).End(xlUp).Row '第1列最后一行
- sh2arr = .Range(.Cells(4, 1), .Cells(MaxRow, MaxCol)).Value
- End With
- '将“列表”工作表和“筛选”工作表相对应的列次分割到数组中
- sh1colarr = Split(Sh1ColList, ",")
- sh2colarr = Split(Sh2ColList, ",")
- ' 按照 筛选 数组的成员数进行循环(不包含标题,从1开始)
- For S = 1 To UBound(sh2arr)
- ' 按照 列表 数组的成员数进行循环(包含标题,从2开始)
- For L = 2 To UBound(sh1arr)
- '判断两个数组的股票代码是否一致
- If sh2arr(S, 1) = sh1arr(L, 1) Then
- '一致时,将列表中的相应列次的数据写入到筛选工作表数组中
- For X = 0 To UBound(sh1colarr)
- sh2arr(S, sh2colarr(X)) = sh1arr(L, sh1colarr(X))
- Next
- Exit For
- End If
- Next
- Next
- '将处理后的数组内容写入到 筛选 工作表中
- sh2.Range("A4").Resize(UBound(sh2arr, 1), UBound(sh2arr, 2)).Value = sh2arr
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|