Excel VBA随笔四

VBA数组:
dim i as Long
dim i

timer:时间 t = timer .... msgbox timer - t 
循环时间长,所以很忌讳在循环中取单元格,可以将单元格的值赋值给string类型变量

数组
dim arr()

arr = range("g1:j200000")

通过arr(第几行,第几列)取值
可以大幅度提升速度

dim arr(1 to 4)
arr(1) = ""
2
3
使用range给arr赋值都是二维的
max(arr)最大值
match(range(""), arr, 0)找出是第几个

重定义数组大小
dim arr()
i = range("a65536").end(lxup).row - 1
redim arr(1 to i)

数组的上限(上标最小为):ubound(arr) 下限(下标最小为)lubound(arr)

使用数组进行排列组合
跳出所有循环 goto 100
for
    for
        for
            if ... then
                goto 100
            end if
        next
    next
next

100

科学计数法转换format(timer-t, "0.000000")


使用activeX控件
按钮控件 属性:caption:文字,enable:可点,  visible:可见

单选按钮:groupname属于哪一组
if sheet1.optionButton1.value = True then ...

微调按钮:value返回值,min最小值
左移或右移了多少 i = sheet2.spinButton1.value
清空选择
optionButton1.value = False
写入题目
label2.caption = i
选中:
optionButton1.value = True

窗体和控件
窗体常用方法:show显示,hide隐藏
隐藏主程序:application.visible=False
杀进程:application.quit

文本框:用户可以输入
密码转星号:passwordChar
保护工作簿
sheet2.visible = xlsheethidden
sheet2.protect "test"

窗体中
if me.textbox1.value = "..." and ... then 
    sheet2.visible = xlsheetvisible
    sheet2.unprotect "test"
当表格关闭之前,隐藏表,保护表

下拉框
sub csh()
userform1.combobox1.addItem "test"
list 数据源列表,addItem增加一个下拉项目,
removeItem移除一个项目
clear全部清除
初始化窗体,激活的时候 call csh()

列表框
包含函数 instr(源数据,被包含的数据),instr("123456", "123")含有则返回1,否则返回0
change事件
me.listbox1.listcount

VBA中的用户信息交互
i = InputBox("请输入名字", "输入框", "在这里写")

dim wb as workbook
str = getopenFilename("excel文件, *.xls*", 2)
if str <> "False" then
    set wb = workbooks.open(str)
end if
dim arr()
arr = getopenFilename("excel文件, *.xls*", 2,,True)
这个arr的下标从1开始
if arr(1) <> "False"
for i = LBound(arr) to UBount(arr)

需要加载宏,不要使用thisworkbook使用:
set wb1 = activeworkbook

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值