Excel VBA

来源:互联网 发布:js protocol buffer 编辑:程序博客网 时间:2024/06/02 15:28
Dim sht As Worksheet        '声明一个工作表类型的变量Dim IntCount As Integer     '声明一个Integer变量IntCountDim sht As Worksheet, IntCount As IntegerDim Str As String 等价于 Dim Str$强制声明变量Option Explicit声明本地变量Sub Test1()    Dim a As String    Static b As IntegerEnd Sub声明一维数组Public | Dim 数组名称(a To b) As 数据类型该数组可保存数据的个数:(b-a+1)个。Dim arr(1 To 100) As ByteDim arr(99) As Byte '该数组有(99-0+1),即100个元素  'OPTION BASE 1声明多维数组Dim arr(1 To 3, 1 To 5) As IntegerDim arr(2, 4) As Integer声明动态数组Sub Test()    Dim a As Integer '定义一个Integer类型的变量,名称为a    '用工作表函数COUNTA求A列中的非空单元格个数,将结果保存在变量a中    a = Application.WorksheetFunction.CountA(Range("A:A"))End SubSub Test()    Dim a As Integer '定义一个Integer类型的变量,名称为a    '用工作表函数COUNTA求A列中的非空单元格个数,将结果保存在变量a中    a = Application.WorksheetFunction.CountA(Range("A:A"))    Dim arr() As String '定义一个String类型的动态数组    ReDim arr(1 To a) '重新定义数组arr的大小End Sub3.5.81. 使用 Array函数创建数组Sub ArrayTest()    Dim arr As variant    arr = Array(3,8,1,9,6,4,7,5)    MsgBox "arr数组的第2个元素为: "& arr(1)End Sub

0 0
原创粉丝点击