gpt4 book ai didi

vba - Excel VBA AutoFit 基于一定范围?

转载 作者:行者123 更新时间:2023-12-04 21:53:22 28 4
gpt4 key购买 nike

我可以使用 Range("A3:D9").EntireColumn.AutoFit根据每列中最宽的列来固定列宽A:D
但是,Range("A3:D9").AutoFit不起作用 - 我想我明白为什么,AutoFit 是一种仅适用于 EntireColumn 的方法! - 我认为?!

有没有办法让它工作 - 使用 AutoFit 来修复基于 的列宽我的范围内每列的最大 col 宽度 而不是整个专栏?

最佳答案

来自 AutoFit manual :

The Range object must be a row or a range of rows, or a column or a range of columns. Otherwise, this method generates an error.



因此,仅针对特定区域自动调整列/行的解决方案是使用:
Range("A3:D9").Columns.AutoFit
Range("A3:D9").Rows.AutoFit

这段代码:
Range("A3:D9").AutoFit

不指定是否应调整列或行。它可能会同时调整两者,但语言的设计者决定抛出一个错误。

关于vba - Excel VBA AutoFit 基于一定范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50044795/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com