【问题标题】:VBA How to autofit row height with merged cells?VBA 如何使用合并的单元格自动调整行高?
【发布时间】:2018-10-27 09:36:55
【问题描述】:

我有一个未在数据高度中设置的动态数据。如何动态设置数据高度中的高度。

sub test()
    Sheets(1).Cells(2, 16).Value = "Process inform HMI finish oil fiber display not show we check found HMI damage after we check no have spare after we move HMI alarm display at control spinning to install. But the type of HMI not same. To convert graphic display.After transfer to HMI and test operation finished. Test system with process is working normal. Process inform HMI finish oil fiber display not show we check found HMI damage after we check no have spare after we move HMI alarm display at control spinning to install. But the type of HMI not same. To convert graphic display.After transfer to HMI and test operation finished. Test system with process is working normal. Process inform HMI finish oil fiber display not show we check found HMI damage after we check no have spare after we move HMI alarm display at control spinning to install. But the type of HMI not same. To convert graphic display.After transfer to HMI and test operation finished. Test system with process is working normal. Process inform HMI finish oil fiber display not show we check found HMI damage after we check no have spare after we move HMI alarm display at control spinning to install. But the type of HMI not same. To convert graphic display.After transfer to HMI and test operation finished. Test system with process is working normal."
End sub

现在显示单元格数据完整数据我如何使用“WrapText”和“AutoFit”,但完整数据显示单元格,但更多的是隐藏在单元格中的单词。行高 409 如何增加单元格高度。

给我示例链接并输出。

【问题讨论】:

  • 我不明白。您的代码自动调整列而不是行。
  • Hi 动态行高设置在每行单元格数据行数上加深以增加行高。
  • 我正在使用marge单元格如何设置行高动态

标签: excel vba


【解决方案1】:

不要使用合并单元格和自动调整,只使用换行文本并将列宽设置为任何所需的数字,这在您的数据上看起来不错。

Sub test()

    Dim row_num
    Dim col_num

    row_num = 2
    col_num = 16

    Columns(col_num).ColumnWidth = 65

    Sheets(1).Cells(row_num, col_num).Value = "Process inform HMI finish oil fiber display not show we check found HMI damage after we check no have spare after we move HMI alarm display at control spinning to install. But the type of HMI not same. To convert graphic display.After transfer to HMI and test operation finished. Test system with process is working  normal. Process inform HMI finish oil fiber display not show we check found HMI damage after we check no have spare after we move HMI alarm display at control spinning to install. But the type of HMI not same. To convert graphic display.After transfer to HMI and test operation finished. Test system with process is working normal.Process inform HMI finish oil fiber display not show we check found HMI damage after we check no have spare after we move HMI alarm display at control spinning to install. But the type of HMI not same.To convert graphic display.After transfer to HMI and test operation finished." _
    & "Test system with process is working normal. Process inform HMI finish oil fiber display not show we check found HMI damage after we check no have spare after we move HMI alarm display at control spinning to install. But the type of HMI not same. To convert graphic display.After transfer to HMI and test operation finished. Test system with process is working normal."

    Sheets(1).Cells(row_num, col_num).WrapText = True

End Sub

编辑版本

您可以检查以下代码以了解自动拟合合并单元格。

A 到 C 列的单元格宽度分别设置为 12,对于高度,文本长度的 45% 的比率取决于此宽度,如果要更改宽度,则还必须更改比率.

Sub test1()


    Sheets(1).Cells(2, 1).Value = " Testing Testing TestingTestingTesting Testing Testing TestingTestingTesting Testing TestingTesting Testing Testing TestingTesting Testing Testing Testing TestingTesting Testing TestingTesting Testing Testing Testing Testing Testing Testing Testing TestingTestingTesting Testing"
    Range("A2:C2").Merge
    Range("A2:C2").WrapText = True

    Columns("A:C").ColumnWidth = 12

    text_length = Len(Sheets(1).Cells(2, 1).Value)
    Rows("2:2").RowHeight = text_length * 0.45


End Sub

【讨论】:

  • Columns(col_num).ColumnWidth = 500 错误 ------------- Microsoft Visual Basic for Applications - -------------------------- 运行时错误'1004':应用程序定义或对象定义错误
  • 尝试将其降低到 180 左右
  • 列的最大宽度只能小于255,而180大约是普通屏幕的宽度,您可能不希望列宽于屏幕本身。
  • 列高怎么增加
  • 自动调整不适用于合并单元格,您必须编写一些自定义函数来检查单元格宽度和字符串长度之间的比例并设置您自己的高度
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-31
  • 1970-01-01
  • 2018-06-28
  • 1970-01-01
  • 2021-02-28
相关资源
最近更新 更多