|
因为我的数据很都有上万行,所以我想用数组或字典方法实现
具体说,比如: 我将数组区域 工作表的内容当作一个数组区域
然后:我经过一定计算后,我只想取这个数组中的arr(*,1)、arr(*,2)、arr(*,6)、arr(*,7)列,数组学得不好,不知如何实现????
- Option Explicit
- '---------------------------------------------------------------------------------------
- ' Procedure : 数据2
- ' Author : hwc2ycy
- ' Date : 2012/12/24
- ' Purpose :
- '---------------------------------------------------------------------------------------
- '
- Sub 数据2()
- Dim arrCon, iRow%, data, result, rg As Range
- On Error Resume Next
- Set rg = Application.InputBox("请用鼠标选择条件区域[N行2列]", , , , , , , 8)
- If rg.SpecialCells(xlCellTypeConstants, xlNumbers + xlTextValues).Count <> rg.Count Then
- MsgBox "条件区域有不非文本数值,请重来"
- Exit Sub
- End If
- If rg.Columns.Count <> 2 Then
- MsgBox "所选的条件区域不是2列,请重来"
- Exit Sub
- End If
- arrCon = rg.Value
- data = Range("a1").CurrentRegion
- If UBound(data) <= 2 Then MsgBox "数据不足": Exit Sub
- Dim i%
- ReDim result(1 To UBound(arrCon), 1 To UBound(data))
- For iRow = 1 To UBound(data)
- For i = 1 To UBound(arrCon)
- result(i, iRow) = data(iRow, arrCon(i, 2))
- Next
- Next
- With Worksheets("结果")
- .Range("a1").CurrentRegion = ""
- .Range("a1").Resize(UBound(data), UBound(arrCon)) = WorksheetFunction.Transpose(result)
- End With
- MsgBox "提取完成"
- End Sub
复制代码
|
|