vba 将列宽扩展到该列中最大值的大小?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11396433/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
expand column width to the size of the largest value in that column?
提问by mezamorphic
In Excel if you double-click a column on its right "border" you can auto-size the width to be the width of the largest value in that column.
在 Excel 中,如果双击右侧“边框”上的列,则可以将宽度自动调整为该列中最大值的宽度。
How does one replicate this in VBA?
如何在 VBA 中复制这一点?
回答by Alex K.
You can use the Macro Recorder to perform the action & see;
您可以使用宏记录器来执行操作并查看;
<range>.entirecolumn.autofit
回答by Francis P
Call the AutoFit
Method of a Column
object.
调用对象的AutoFit
方法Column
。
Like so:
像这样:
ActiveSheet.UsedRange.Columns.AutoFit
or like so:
或者像这样:
Columns("A:A").EntireColumn.AutoFit