|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
F列内容换行符的位置并不是理想的换行位置,有些行即使有换行符但内容也较多,一行也显示不下,要把各种因素考虑进去就要花些时间了,且你的表格中还有各种合并单元格,现在换个思路帮你解决下,就是取消所有的换行符,设定每行容纳的字符数量,这样就容易计算出自动换行的行数,因为夹杂全角、半角,所以计算行数和显示行数可能有一些出入。
Sub AutoRowHeight()
Cells.Replace What:=Chr(10), Replacement:=""
Cells.Replace What:=Chr(13), Replacement:=""
Dim mr As Range, last&, rw&
cs = 54 '每行容纳字符数量设定为54(27个汉字或全角字符),自己根据列宽调整。汉字全角字符占用2字节。
last = Sheet1.Range("F" & Rows.Count).End(xlUp).Row
For Each mr In ActiveSheet.Range("F7:F" & last)
If LenB(mr.Value) Mod cs = 0 Then
rw = LenB(mr.Value) / cs
Else
rw = Int(LenB(mr.Value) / cs) + 1
End If
If rw = 0 Then rw = 1
mr.MergeArea.RowHeight = 15 * rw
mr.HorizontalAlignment = xlCenter
Next
End Sub
|
|