摘要: Sub fornext循环()Dim i!, j!For i = 1 To 100 step 1(1可以默认不写)j = j + iNextMsgBox jEnd Sub 阅读全文
posted @ 2015-09-15 16:14 混混的IT生涯 阅读(119) 评论(0) 推荐(0) 编辑
摘要: 当需要处理集合成员的时候,一般会用这个,实际上就是处理对象Sub foreachnext循环()Dim rng As Range, n!For Each rng In Sheet1.Range("a2:a6")If rng = "a1" Then rng.Interior.ColorIndex = ... 阅读全文
posted @ 2015-09-15 16:11 混混的IT生涯 阅读(139) 评论(0) 推荐(0) 编辑
摘要: Sub util实例()Dim rs%rs = 2Do Until Cells(rs, 2) = ""If Cells(rs, 2) >= 90 Then Cells(rs, 3) = "good"rs = rs + 1LoopEnd Sub 阅读全文
posted @ 2015-09-15 15:59 混混的IT生涯 阅读(233) 评论(0) 推荐(0) 编辑
摘要: Sub while实例()Dim rs%rs = 2Do While Cells(rs, 2) ""If Cells(rs, 2) >= 90 Then Cells(rs, 3) = "good"rs = rs + 1LoopEnd Sub 阅读全文
posted @ 2015-09-15 15:55 混混的IT生涯 阅读(185) 评论(0) 推荐(0) 编辑
摘要: 循环语句,直到满足某个条件Sub 事例()Dim a%Doa = a + 1If a > 10 ThenMsgBox a & "大于10"Exit DoEnd IfLoopEnd Sub 阅读全文
posted @ 2015-09-15 15:47 混混的IT生涯 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 根据表达式的值来决定执行几组语句中的其中之一Sub select多条件判断()Dim s$s = "a"Select Case sCase "a" MsgBox "我是a"Case "b" MsgBox "我是b"Case Else MsgBox "我是未知"End SelectEnd Sub 阅读全文
posted @ 2015-09-15 15:40 混混的IT生涯 阅读(300) 评论(0) 推荐(0) 编辑
摘要: Sub 判断()Dim a%, b%a = 1b = 2If (a > b) ThenMsgBox ("a比b大")ElseMsgBox ("a比b小")End IfEnd Sub还有一种IFF的用法:Sub iff判断()Dim a%, b%, c$a = 1b = 2c = IIf((a > b... 阅读全文
posted @ 2015-09-15 15:29 混混的IT生涯 阅读(131) 评论(0) 推荐(0) 编辑
摘要: 注释 简写 占用内存integer: 整型 % 2Bytesingle: 单精度 ! 4Bytedouble: 双精度 # 8Bytelong: 长整型 & 4Bytesting: 字符型 ... 阅读全文
posted @ 2015-09-15 15:18 混混的IT生涯 阅读(92) 评论(0) 推荐(0) 编辑
摘要: Sub 常量()Const pi = 3.1415926End SubSub 变量()Dim a As Integera = 39a = 323End Sub注意事项:vba允许使用未定义的变量,默认是变体变量(variant)变量的强制声明:option explicit不能用保留字以字母开头不能... 阅读全文
posted @ 2015-09-15 15:05 混混的IT生涯 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 方法:实际上就是对对象的操作,他是一种in个动作,一种行为。Sub choose()Range("a1:a10").Select'如果没有写工作表名,默认活动工作表End SubSub copy()Sheet1.Range("a1:a10") = 1 '将1写入a1:a10区域Sheet1.Rang... 阅读全文
posted @ 2015-09-15 15:02 混混的IT生涯 阅读(111) 评论(0) 推荐(0) 编辑
摘要: Sub show()MsgBox "我是一个弹出框"End Sub过程可以当作宏来使用 阅读全文
posted @ 2015-09-15 14:39 混混的IT生涯 阅读(112) 评论(0) 推荐(0) 编辑