人气 5484

[Excel技巧] Excel vba设置行高及自动行高 [复制链接]

精益人 2017-10-9 15:17:08
在Excel工作表中,有时会因为文本内容的长度影响阅读。需要调整行高来显示全部信息。excel对单元格设置行高很简单。一般情况下,都是通过点击菜单:格式——行——行高,然后进行设置。这里我们介绍一下用Excel vba来设置Excel工作表的行高
1、建立基础数据表及两个按钮
1507534171468185.png (13.73 KB, 下载次数: 0, 售价: 4 金钱)
2、为按钮添加代码设置行高的代码:  
Sub 设置行高()
  Dim h As Long, r As Long, i As Integer, n As Integer  Dim ws1 As Worksheet  h = Application.InputBox(prompt:="请输入所选行的高度:", Title:="输入行高", Type:=1)   Set ws1 = ActiveSheet  n = Selection.Rows.Count  r = ActiveCell.Row  For i = 1 To n    ws1.Rows(r + i - 1).RowHeight = h  Next  Set ws1 = Nothing
End Sub
自动行高代码:
Sub 自动调整行高()
  Selection.Rows.AutoFit
End Sub
3、运行效果图
1507534331109042.gif (129.2 KB, 下载次数: 0, 售价: 3 金钱)
您需要登录后才可以回帖 登录 | 立即注册

QQ|手机版|精益人 ( 沪ICP备19004111号-1 )

GMT+8, 2024-5-18 23:46 , Processed in 0.262828 second(s), 23 queries .

Powered by Lean.ren X3.5 Licensed  © 2001-2030 LEAN.REN