VBA入门

个人在工作中喜欢登记台账,一般使用excel,最近在使用一份excel的台账做总结的时候,发现普通的公式无法满足需求,故入坑vba,一发不可收拾。
把一些基本的vba语法记录一下,以备查。

变量定义

使用Dim声明

1
2
3
Dim a as Long
Dim b as Date
Dim c as String

For

1
2
3
4
For i = 0 to 10 [Step +2]
'do something
'use Exit For to Exit
Next

If

1
2
3
4
5
6
7
If condition Then
'do something
Elif
'do something
Else
'do something
EndIf

获取单元格或者区域

1
2
3
4
Sheets("").Cells(row, col)
Sheets("").Range("A1")
Sheets("").Range("A1:B2")
Sheets("").Range(Cells(row, Col), Cells(row, col))

排序Sort

单元格样式.


VBA入门
http://blog.colorccm.com/2019/07/26/it/first_vba/
作者
Chibao Chan
发布于
2019年7月26日
许可协议