我从一位非常优秀的绅士那里得到了关于这段代码的帮助。这部分代码基本上编写了一个跨越两列,合并和换行文本的标题。我为不同长度的标题生成这个excel提取物。对于某些报告,如果标题较短,则高度为常规单元格,对于其他标题,其高度为x3,即使标题的长度不需要那么高的高度。有没有办法让我指明我希望ROW始终是......比常规行高的3倍高。我不希望它因报告而异。无论字符串的长度如何,我希望它看起来一样。如果我使用.merge和.wraptext = true
那就是那种可能吗?Do While Not g_RS3.EOF
With xlSheetInsurance.Cells(xlRow, xlCol)
.Value = g_RS3("ShortLabel")
With .Resize(1, 2)
.WrapText = True
.Merge
End With
.Offset(1, 0).Resize(1, 2) = Array("# Clients", "# Students")
.Offset(2, 0).Resize(1, 2).ClearContents
With .Offset(0, 1)
.Resize(1, 2).Merge
.Value = "TOTAL"
.Offset(1, 0).Resize(1, 2) = Array("# Clients", "# Students")
.Offset(2, 0).Resize(1, 2).Formula = _
"=SUMIFS(" & xlSheetInsurance.Range(.Parent.Cells(xlRow + 2, xlStartCol), .Parent.Cells(xlRow + 2, xlCol + 1)).Address(0, 1) & Chr(44) & _
xlSheetInsurance.Range(.Parent.Cells(xlRow + 1, xlStartCol), .Parent.Cells(xlRow + 1, xlCol + 1)).Address(1, 1) & Chr(44) & _
.Parent.Cells(xlRow + 1, xlCol).Address(1, 0) & Chr(41)
.Offset(2, 0).Resize(1, 2).AutoFill .Offset(2, 0).Resize(7, 2) ' AutoFill formula for all Types
.Offset(2, 0).Resize(7, 2).Borders(xlEdgeRight).LineStyle = xlContinuous
End With
With .Resize(2, 4)
.Font.Bold = True
.WrapText = True
.VerticalAlignment = xlCenter
.HorizontalAlignment = xlCenter
.Borders.Weight = xlThin
End With
End With
xlCol = xlCol + 2
g_RS3.MoveNext
Loop
答案 0 :(得分:2)
这样可以满足您的需求:
With .Resize(1, 2)
.WrapText = True
.Merge
.RowHeight = 45
End With