Reputation: 242
Hello my question is how to set a minimum Height for Cells in an Excel Sheet? Right now it looks like:
But it should look like: I tried so far to set the cell height with:
excelSheet.Columns[1].ColumnWidth = 16.14;
and then the excelSheet.Columns[1].Autofit()
but it gets overriden so i was hoping to find a way to set a minimum Height for the Autofit. Then i tried to google for it but nothing helpful showed up. For the cells they get merged with
// Merge the Cells for the summary Box
for (int i = 2; i <= 10; i++)
{
excelSheet.Range[excelSheet.Cells[startColumn + i, 1], excelSheet.Cells[startColumn + i, 10]].Merge(Missing.Value);
}
and then a linebreak with excelSheet.get_Range("A" + lineBreakAreaTop, "J" + lineBreakAreaBottom).WrapText = true;
Mabey this has something to do with it.
So any help or advise would be great an thanks for your Time. And sorry for my english.
Upvotes: 1
Views: 2708
Reputation: 1
For Office 365, please add one more line in the beginning.
We need to activate the developer tab from File>Options>Customized_Ribbon
Then this Macro is to be added to the 'view_code' window
Make it operable in all sheets from the left pane,
And convert file to xlsm format for the macro to be enabled.
Upvotes: 0
Reputation: 17415
To simulate a Min Height
setting in the excel rows I wrote the following simple code and use it by the bellow instruction in my excel files:
Excel
View Code
button in the opened window to open the Editor
Copy-Paste
the bellow codes in the Editor
Codes
Private Sub Worksheet_Change(ByVal Target As Range)
'Cells.Rows.AutoFit
For rowCounter = 1 To 500
If Rows(rowCounter & ":" & rowCounter).EntireRow.RowHeight < 15 Then
Rows(rowCounter).EntireRow.RowHeight = 15
End If
Next
End Sub
Note 1: If you want to force the worksheet to apply
Rows AutoFit function
on changes too, then you can uncomment it by removing the'
sign from beginning of its code line in the above code.Note 2: If the row count of the data is more than
500
in your excel file, then increse this number in the above code to an appropriate value.
Editor
Upvotes: 1