vba语法

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;

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值