首页 > 编程语言 > 详细

excel vba

时间:2020-07-20 01:03:00      阅读:109      评论:0      收藏:0      [点我收藏+]

excel 开发者工具 visual Basic (文件格式需要保存成带宏(动作的录制 一般用于重复的工作)的)

‘子过程
Sub aa()
‘‘对象方法
‘Range("a1:a10").Select
‘
‘‘常量 Const 变量 Dim 定义
‘Const Pi = 3.14
‘Dim a As Integer
‘a = 200
‘Debug.Print a * Pi

‘循环+if
‘Do
‘Dim a As Integer
‘a = a + 1
‘If a > "10" Then
‘Exit Do
‘End If
‘Loop

‘循环+while
‘Dim a As Integer
‘a = 1
‘Do While Cells(a, 1) <> ""
‘If Cells(a, 1) >= 10 Then Cells(a, 3) = "b"
‘a = a + 1
‘Loop

‘循环+until 注意字符连接利用 & (连接前后有空格)
‘Dim a As Integer
‘a = 1
‘Do Until Cells(a, 1) = ""
‘Sheet1.Range("a" & a & ":c" & a & "").Interior.ColorIndex = 7
‘a = a + 2
‘Loop

‘foreach 操作对象 Next i 计数变量
‘Dim arn As Range
‘For Each arn In Sheet1.Range("a1:a5")
‘If arn.Value > 20 Then arn.Interior.ColorIndex = 3
‘Next
‘End Sub

‘foreach 操作对象 Next i 计数变量找到对应满足的位置
For i = 1 To 5
If Cells(i, 1) = 20 Then Exit For
Next i
MsgBox i
End Sub

‘end 结束一个过程或块 End、 End Function、End If、End Select
‘exit 是退出当前语句 Exit Do、Exit For、Exit Function、Exit Sub


excel vba

原文:https://www.cnblogs.com/leifonlyone/p/13341892.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!