VBA动态设置Excel斜线表头的方法
时间:2022-10-12 00:06:33
如果您需要直接绘制斜线表头的方法,那就得使用VBA的方法,以下内容与此相关,请继续阅读。
用“控件工具箱”中的“命令按钮”控件,在工作表中绘制一个命令按钮,将“Caption”属性改为“直接制作斜线表头”,双击该按钮,在“Click”事件中编写代码,其中关键代码如下。
关键代码:
'获取行标题和列标题
Dim icol, irow As String
icol=InputBox("请输入斜线单元格的行标题", 行标题)
irow=InputBox("请输入斜线单元格的列标题", 列标题)
Selection.Value = icol + " " + irow
'判断字符串是否符合规定
If Len(icol) = 0 or Len(irow) = 0 Then
MsgBox ("输入的标题为空!")
Exit Sub
End If
'判断选区是否只有一个单元格
If Selection.Count <> 1 Then
MsgBox ("请选择一个单元格再执行此操作!")
Exit Sub
End If
'设置左上至右下的斜线
With Selection.Borders(xlDiagonalDown)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
此功能的使用方法如下:
代码编写好以后,需要插入斜线表头的时候,先选中需要插入斜线表头的单元格(如果选中的单元格超过一个,系统会给出错误提示),单击“直接制作斜线表头”按钮,系统会提示输入表头的行、列标题,分别输入表头的行标题(例如成绩)和列标题(例如班级)即可。
标签:VBA动态设置Excel斜线表头的方法
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
word页面背景如何更改?
2023-08-06 07:41:30
![](https://img.aspxhome.com/file/2023/3/24213_0s.jpg)
Excel教你巧用热键任移方向
2023-02-05 22:44:00
![](https://img.aspxhome.com/file/2023/3/37123_0s.png)
Word 2007中批量快速插入图片技巧
2022-12-25 12:51:05
![](https://img.aspxhome.com/file/2023/7/22387_0s.jpg)
创建用户在Word2007中填写的窗体
2023-12-12 14:25:54
![](https://img.aspxhome.com/file/2023/8/20658_0s.jpg)
Excel2013怎么设置数据以百万单位显示?
2023-11-18 04:15:32
![](https://img.aspxhome.com/file/2023/2/36062_0s.jpg)
Word目录............怎么打?
2022-05-06 14:52:02
![](https://img.aspxhome.com/file/2023/0/31270_0s.png)
word页面设置16开怎么设置
2023-10-12 17:57:09
![](https://img.aspxhome.com/file/2023/1/35931_0s.png)
word更改了一个标题的颜色,怎样使其它标题的颜色自动改变
2023-07-29 12:39:34
![](https://img.aspxhome.com/file/2023/2/35302_0s.png)
Win10系统麦克风没有声音要怎么办?
2023-12-13 05:52:12
![](https://img.aspxhome.com/file/2023/3/51503_0s.jpg)
Excel2010怎么添加单元格批注
2023-08-31 17:47:24
![](https://img.aspxhome.com/file/2023/1/36501_0s.jpg)
wps文档怎样在第一行有下划线?
2023-08-09 10:05:16
![](https://img.aspxhome.com/file/2023/1/53651_0s.jpg)
word发送错误报告怎么办
2022-12-01 23:26:12
![](https://img.aspxhome.com/file/2023/2/34222_0s.png)
计算机二级考试真题-Excel-王芳-图书销售情况表
2023-10-31 05:35:50
Word怎么插入连续图片列表?Word插入连续图片列表的方法
2023-03-31 23:27:59
![](https://img.aspxhome.com/file/2023/0/30890_0s.png)
excel打印怎么横竖转换
2023-09-20 00:09:47
![](https://img.aspxhome.com/file/2023/5/36785_0s.jpg)
word 查找的通配符使用技巧及实例教程
2022-07-20 06:06:59
iOS 14中如何捏制个性化拟我表情?
2023-10-31 15:20:32
![](https://img.aspxhome.com/file/2023/0/46260_0s.png)
怎么激活2021最新office365?office365激活密钥+激活工具推荐
2023-05-29 19:55:52
![](https://img.aspxhome.com/file/2023/4/14944_0s.jpg)
Win10打印文件出现挂起情况怎么办?打印文件出现挂起情况的解决方法
2023-06-04 21:39:19
![](https://img.aspxhome.com/file/2023/6/46406_0s.jpg)
word2019中旋转图片和调整图片大小的方法图解教程
2022-10-03 00:12:34
![](https://img.aspxhome.com/file/2023/0/35180_0s.jpg)