VBA入门
一、宏程序语句
运行后可以完成一个功能
Sub text() '开始语句
Range("a1") = 100
End Sub '结束语句
条件判断
二、条件判断
1、if条件判断
Sub panduan()
If Range("a1").Value > 0 Then
Range("b1") = "正数"
ElseIf Range("a1") = 0 Then
Range("b1") = "零"
Else
Range("b1") = "负数"
End If
End Sub
2、select条件判断
Sub selectpanduan()
Select Case Range("a1").Value
Case Is > 0
Range("b1") = "正数"
Case Is = 0
Range("b1") = 0
Case Else
Range("b1") = "负数"
End Select
End Sub
循环
三、循环
1、第一种循环,定义变量的范围
Sub t1()
Dim x As Integer '定义x为一个整数型变量
For x = 1 To 12 'for 定义x的范围
Range("c" & x) = Range("a" & x) * Range("b" &