VBA 选择工作表中的所有列并在 Excel 2010 中自动调整所有列的宽度
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24154232/
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
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 18:19:02 来源:igfitidea点击:
VBA to select all columns in a worksheet and auto adjust all columns width in Excel 2010
提问by user3720702
I have a worksheet with with over 1000 columns. How can I select all columns in that sheet and auto adjust every column width. I tried
我有一个超过 1000 列的工作表。如何选择该工作表中的所有列并自动调整每个列的宽度。我试过
Sheets(1).Select
Selection.EntireColumn.AutoFit
But it didn't work. Any ideas?
但它没有用。有任何想法吗?
回答by Mark Balhoff
Try this...
尝试这个...
Sheets(1).UsedRange.Columns.AutoFit
回答by gth826a
You can use
您可以使用
Cells.Columns.Autofit
or, if you're not on the ActiveSheet then
或者,如果您不在 ActiveSheet 上,则
Sheets(name_or_number).Columns.Autofit
回答by kaushal kumar
Option Explicit
Sub Auto_Fit()
Dim sh As Worksheet
For Each sh In ThisWorkbook.Worksheets
sh.Columns.AutoFit
Next sh
End Sub