opelhatza
opelhatza

Reputation: 242

Any way to set minimum Cell Height in an Excel Sheet?

Hello my question is how to set a minimum Height for Cells in an Excel Sheet? Right now it looks like: Excel Sheet

But it should look like:How it should look 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

Answers (2)

Nirupam
Nirupam

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

Ramin Bateni
Ramin Bateni

Reputation: 17415

Simulate Min Height in Excel

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:

  1. Open your excel file and Press Alt+F11 in Excel
  2. Click on View Code button in the opened window to open the Editor

enter image description here

  1. 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

enter image description here

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.

  1. Save it by Press Ctrl+S in the Editor
  2. Go back to the sheet and change any cell value and leave the cell, now you should see the result ;)

Upvotes: 1

Related Questions