代码运行结果:
![VBA案例精选 批量设置单元格格式](https://p3-tt.byteimg.com/origin/pgc-image/affa8301e20341bea072b219a261c1cc.png?from=pc)
代码截图:
![VBA案例精选 批量设置单元格格式](https://p6-tt.byteimg.com/origin/pgc-image/a2447ee3daa846d28666d65b37ae130e.png?from=pc)
代码文本:
Public Sub 技巧()
Dim myRange As Range
Set myRange = Range("A1:F3") '指定任意单元格区域
MsgBox "下面将单元格区域 " & myRange.Address(False, False) _
& " 的格式删除。"
myRange.ClearFormats '删除格式
MsgBox "下面将单元格区域 " & myRange.Address(False, False) _
& " 自动套用<会计1>的格式。"
myRange.AutoFormat xlRangeAutoFormatAccounting1
Set myRange = Nothing
End Sub
注释:
设置单元格格式不只可以设置为会计,日期等均可以设置,根据既定的格式更改代码,变成自己所需要的格式内容。
VBA编辑神器放送
VBA编程懒人神器推荐 VBA代码助手 可以极大提高编程速度,降低编程门槛欢迎使用
VBA密码破解 VBA代码对齐 VBA代码混淆保护加密 代码库输入提示 VBA模块隐藏
下载链接:http://excel880.com/blog/archives/11297