ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
楼主: FENGJUN

[数组技巧接龙......]大家能否将遇到过的数组技巧简单写一下?

[复制链接]

TA的精华主题

TA的得分主题

发表于 2006-1-9 18:41 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助

Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select

可以写为:

Sheets(Array(1, 2, 3)).Select

TA的精华主题

TA的得分主题

发表于 2006-1-24 16:12 | 显示全部楼层

a = Range("A1:B4").Value 在VBA中试用会出错?
Range("A1:B4").Value=a 能用


TA的精华主题

TA的得分主题

发表于 2006-1-24 16:45 | 显示全部楼层
我是数组盲,跟着学学了!

TA的精华主题

TA的得分主题

发表于 2006-1-25 13:18 | 显示全部楼层

TA的精华主题

TA的得分主题

发表于 2006-1-25 13:51 | 显示全部楼层

对一个数组提取非重复元素进行求和

Function UniqueSum(ByVal ArraySource, ByVal IndexColumn As Integer, ByVal SumColumn As Integer) As Variant
'IndexColumn refers to the column of ArraySource that you want to extract unique items
'SumColumn refers to the column which stored values that you want to do sum

Dim arr()
Dim i, x, k As Long, ds As Object
Set ds = CreateObject("scripting.dictionary") 'create a dictionary to extract unique items
x = 1 'use to record the index of unique item
For i = 1 To UBound(ArraySource, 1)
On Error Resume Next
ds.Add ArraySource(i, IndexColumn), x
If Err.Number = 0 Then 'no duplicate
ReDim Preserve arr(1 To 2, 1 To x) 'make it as horizonal array
arr(1, x) = ArraySource(i, IndexColumn)
arr(2, x) = ArraySource(i, SumColumn)
x = x + 1
Else 'found duplicated item
k = CLng(ds.Item(ArraySource(i, IndexColumn))) 'get the index
If arr(2, k) = "#Err" Or TypeName(ArraySource(i, SumColumn)) = "String" Then
arr(2, k) = "#Err"
Else
arr(2, k) = arr(2, k) + ArraySource(i, SumColumn) 'make summarization
End If
End If
Err.Clear: On Error GoTo 0
Next i
UniqueSum = Application.Transpose(arr) 'transpose horizonal array to vertical
End Function

TA的精华主题

TA的得分主题

发表于 2006-3-7 12:00 | 显示全部楼层

Sheets(Array(1, 2, 3)).Select 高 !

以前只會:

Sheets(Array("Sheet1", "Sheet2", "Sheet3")).Select

TA的精华主题

TA的得分主题

发表于 2006-8-15 06:48 | 显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件       ★免费下载 ★       ★ 使用帮助
数组我最想从最简单的开始学,有系统点的最好,我渴望

TA的精华主题

TA的得分主题

发表于 2006-8-15 09:19 | 显示全部楼层
QUOTE:
以下是引用cooloaky在2006-1-25 13:51:42的发言:

对一个数组提取非重复元素进行求和

Function UniqueSum(ByVal ArraySource, ByVal IndexColumn As Integer, ByVal SumColumn As Integer) As Variant
    'IndexColumn refers to the column of ArraySource that you want to extract unique items
    'SumColumn refers to the column which stored values that you want to do sum
    
    Dim arr()
    Dim i, x, k As Long, ds As Object
    Set ds = CreateObject("scripting.dictionary")       'create a dictionary to extract unique items
    x = 1       'use to record the index of unique item
    For i = 1 To UBound(ArraySource, 1)
        On Error Resume Next
        ds.Add ArraySource(i, IndexColumn), x
        If Err.Number = 0 Then      'no duplicate
            ReDim Preserve arr(1 To 2, 1 To x)      'make it as horizonal array
            arr(1, x) = ArraySource(i, IndexColumn)
            arr(2, x) = ArraySource(i, SumColumn)
            x = x + 1
        Else        'found duplicated item
            k = CLng(ds.Item(ArraySource(i, IndexColumn)))      'get the index
            If arr(2, k) = "#Err" Or TypeName(ArraySource(i, SumColumn)) = "String" Then
                arr(2, k) = "#Err"
            Else
                arr(2, k) = arr(2, k) + ArraySource(i, SumColumn)       'make summarization
            End If
        End If
        Err.Clear: On Error GoTo 0
    Next i
    UniqueSum = Application.Transpose(arr)      'transpose horizonal array to vertical
End Function

能不能请高手中文注释一下这段语句,觉得很有意思可是没有怎么看懂。

TA的精华主题

TA的得分主题

发表于 2006-8-15 09:31 | 显示全部楼层

1,取工作表区域的绝对引用公式到数组:arr=[a1:c5].Formula

2,取工作表区域的相对引用公式到数组:arr=[a1:c5].Formular1c1

3,取工作表区域的转置到数组:arr=Application.Transpose([a1:c5])
    
数组间也可以转置:arr1=Application.Transpose(arr)

4,取数组arr的第n列赋值到某列区域:[e1:e5]=Application.Index(arr, , n)
    
或者赋值产生一个新数组:arr1=Application.Index(arr, , n)  

5,同理,取数组arr的第n行赋值到某行区域:[a6:c6]=Application.Index(arr,n , )
    
或者赋值产生一个新数组:arr1=Application.Index(arr, n, ) 

这是我以前在网上抄的,和大家分享。也不知道是那个前辈规集的了,不要说盗版哈

TA的精华主题

TA的得分主题

发表于 2006-8-15 09:32 | 显示全部楼层

1,取工作表区域的绝对引用公式到数组:arr=[a1:c5].Formula

2,取工作表区域的相对引用公式到数组:arr=[a1:c5].Formular1c1

3,取工作表区域的转置到数组:arr=Application.Transpose([a1:c5])
    
数组间也可以转置:arr1=Application.Transpose(arr)

4,取数组arr的第n列赋值到某列区域:[e1:e5]=Application.Index(arr, , n)
    
或者赋值产生一个新数组:arr1=Application.Index(arr, , n)  

5,同理,取数组arr的第n行赋值到某行区域:[a6:c6]=Application.Index(arr,n , )
    
或者赋值产生一个新数组:arr1=Application.Index(arr, n, ) 

这是我以前抄的,给大家分享,也不知道是那个前辈写的了,不要说我抄袭哈。

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

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-5-18 12:45 , Processed in 0.042910 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

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