Excle中range的一些用法

以下是一些range的简单用法

Sub aa()
'-===============================================
 '给B列设置填充颜色为黄色
 Range("B:B").Select
 With Selection.Interior
 .Color = 65535
 End With
 '给A1录入"我是孙悟空"
 Range("A1").Select
 ActiveCell.FormulaR1C1 = "我是孙悟空"
 
 '--==============================================
 '不相邻区域,使用,表示加选 设置颜色为黑色
 Range("F13:G14,I13:I14").Select
 With Selection.Interior
 .Color = 15
 End With
 
 '--==============================================
'不相邻区域,空格的话表示2个区域相交,设置为绿色
 Range("K14:K21,K18:M21").Select
 With Selection.Interior
 .Color = 5287936
 End With
 
 '--==============================================
 '单元格的相对引用写法 设置为橙色
 Range("F4:G8").Range("a1").Select
 With Selection.Interior
 .ThemeColor = xlThemeColorAccent6
 End With
 
 '--==============================================
 'range的变量支持
 Dim s%
 s = 3
 Range("A" & s).Select
 Range("c3:e5")(2).Select
 With Selection.Interior
.ThemeColor = xlThemeColorLight2
 End With
 
 ActiveWorkbook.Save '保存
End Sub

在EXCLE中运行后截图如下:

原文地址:https://www.cnblogs.com/OliverQin/p/6198441.html