option explicit '强制声明变量
Sub 修改单元格()
dim a,b,c
Const PI = 3.14159 '常量
Dim r1 As Range '定义一个range类型的变量
Set r1 = Range(Cells(1, 2), Cells(1, 5)) '1行2列到1行5列
x = cells(3,1) '得到指定行列的值
Dim r As Range '定义一个range类型的变量
Set r = Range("a1:a4") 'a1单元格到a4单元格
r.Interior.Color = RGB(255, 255, 0) '设置单元格颜色
r.Merge '合并单元格
r.UnMerge '取消合并单元格
r.Font.Size = 18 '设置字号
r.Font.Color = RGB(255, 255, 233) '设置字体颜色
r.Font.Bold = True '加粗
r.Font.Italic = False '不倾斜
With r.Font 'with语法
.Size = 22
.Bold = True
End With
End Sub
-------------------------------------循环-------------------------------------
sub aaa()
dim i = 1
for i=11 to 20 step 1 '如果步长为1,那么step 1可以不写
cells(i,6) = cells(i,6)/100
next i 'i可以不写
end sub
-------------------------------------if语句-------------------------------------
if scoure >=60 then
cells(1,1)="及格"
else
cells(1,1)="不及格"
end if
if score >= 85 then
cells(1,1) = "a"
elseif score>=75 then
cells(1,1) = "b"
elseif score>=65 then
cells(1,1) = "c"
else
cells(1,1) = "d"
end if;