打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Excle工作表基本操作

区域也是Excel工作表的基本操作对象,其操作也比较简单,看下面的代码

Sub test()
Range("A1:B2").Select '选中A1到B2单元格
Range("A1:B2").Interior.Color = vbRed '设置A1到B2单元格的底色为红色
Range("A1:B2").Merge '合并A1到B2单元格
End Sub

下面的代码是设置边框用的

Sub Macro1()

Range("A1:B2").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone  '斜线无
Selection.Borders(xlDiagonalUp).LineStyle = xlNone    '斜线无
With Selection.Borders(xlEdgeLeft)                    '左边线
.LineStyle = xlContinuous          '线条类型
.ColorIndex = 0                             '颜色
.TintAndShade = 0                      '渐变色
.Weight = xlThin                          '线条粗细
End With
With Selection.Borders(xlEdgeTop)        '顶边线
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)     '底边线
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)      '右边线
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)  '里坚线
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)  '里横线
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub

代码中selection代表表格中被选中的区域,在上面的代码中即range("A1:B2")。对于一些设置格式的代码通常是不用自己来写的,只要录制一个宏就可以了,关于怎么录制宏请参见录制宏

 

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Excel单元格边框线设置4
用VBA为选定的单元格加边框
C#.net VSTO Excel开发中一些常用方法
Excel
【VBA】一键生成报表
ADO把Recordset导入EXCEL后打印~ VB / 数据库(包含打印,安装,报表)...
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服