问题
I have a sheet with 2 tables. Each table has a header that I want to be a height of 30 while all table rows are the standard 15. When I add a row to the top table, the bottom table gets pushed down. The header Height on the bottom table picks up the height of the new spreadsheet row. Is there a way to make the bottom table keep its header height at 30? Here is my code to add rows to the top table.
Set tblAssemblies = Worksheets("Summary").ListObjects("Table1")
Count = 1
Do
tblAssemblies.ListRows.Add AlwaysInsert:=True
Count = Count + 1
Loop While Count <= Target.Value - tblAssembliesRows
This pushed the bottom table down, but not the formatting of the sheet row for the header height. Any Ideas?
Rich
回答1:
HeaderRowRange.RowHeight
I've noticed, and you didn't mention, that the '30-height-row moves' into the first table. This should be corrected, too.
Option Explicit
Sub HeaderRowRangeRowHeight()
With Worksheets("Summary")
.ListObjects(2).HeaderRowRange.RowHeight = 30
.ListObjects(1).DataBodyRange.RowHeight = 15
.ListObjects(1).TotalsRowRange.RowHeight = 15
End With
End Sub
回答2:
I am not sure where Target's range is in reference to the header of the table in question, but you could do something like
rows(target.row).rowheight = 22.5
If your header, for example, is always three rows below the Target, then you would just add 3:
rows(target.row + 3).rowheight = 22.5
来源:https://stackoverflow.com/questions/53179158/how-to-keep-the-row-height-constant-when-a-table-is-pushed-down-on-the-sheet