变量
Sub 加法变量()
i = Cells(2, 2)
Cells(i, 9) = Cells(i, 5) + Cells(i, 7) '利用变量来控制
End Sub
计算半径,面积和体积
Sub 求面积和体积()
Radius = Cells(4, 3)
r = Radius
Square = 4 * r * r * 3
Cells(4, 4) = Square
volume = 4 / 3 * r * r * r * 3
Cells(4, 5) = volume '大小写不敏感
End Sub
常量
Option Explicit '强制申明,变量只能用一次
Sub 求面积和体积()
Dim Radius, r, square, volume
Const pi = 3.14 '申明常量,不允许变动
Radius = Cells(4, 3)
r = Radius
square = 4 * r * r * pi
Cells(4, 4) = square
volume = 4 / 3 * r * r * r * pi
Cells(4, 5) = volume '大小写不敏感
End Sub
来源:CSDN
作者:高开低走。
链接:https://blog.csdn.net/qq_43568982/article/details/103738118