简体   繁体   English

如何使用VBA Excel中的宏调整合并单元格的行高?

[英]How can I adjust the row height of merged cells using a macro in vba excel?

I made a excel sheet, which serves as a questionnaire. 我制作了一张Excel工作表,用作调查表。 To allow extensive answes and adjust the design, I have merged cells. 为了允许广泛的烦恼和调整设计,我合并了单元格。 The problem I encounter now is that the row height does not adjust automatically. 我现在遇到的问题是行高不会自动调整。 I have therefore written a short macro to solve this issue. 因此,我写了一个简短的宏来解决这个问题。 However, this macro only works on single cells and does not work on the merged cells. 但是,此宏仅适用于单个单元格,不适用于合并的单元格。 Therefore, I would like to know how I can solve this. 因此,我想知道如何解决这个问题。 How can I adjust the row height of merged cells using a macro in vba excel? 如何使用VBA Excel中的宏调整合并单元格的行高?

Thank you for your help! 谢谢您的帮助!

As always, it would be helpful if you posted your macro, but I am guessing you're trying to use the .entirerow.autofit command? 与往常一样,如果发布宏将很有用,但是我猜您正在尝试使用.entirerow.autofit命令吗? If so, I don't believe this function evaluates a merged cell. 如果是这样,我不相信该函数会评估合并的单元格。 (Someone correct me if I'm wrong!) (如果我错了,请纠正我!)

You might want to consider using "Center Across Range" instead of merging cells. 您可能要考虑使用“跨中心范围”而不是合并单元格。 Or you might want to create a rule to loop through cells to check character length or if the "enter key" CHR(10) was entered, and size based on that. 或者,您可能想创建一个规则以循环遍历单元格以检查字符长度或是否输入了“输入键” CHR(10) ,并根据该尺寸确定大小。 Example: 例:

        Sub TestEachCl()
        Dim CL As Range

        'Make sure to include the intersect with usedrange, 
        'otherwise this will take much longer than necessary.
        For Each CL In Intersect(Rows(20), ActiveSheet.UsedRange).Cells

        If InStr(1, CL.Formula, Chr(10)) > 0 Then
        'enter key exists in a cell
        CL.EntireRow.Height = 30
        'probably want to close the loop or have it not do 
        'anything else once it has reached max height, 
        'so it doesn't reduce the size

        End If

        Next CL

        End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM