![]() In the end, what you want to do and what Excel is capable of doing might not match exactly, but I think you should be able to get done what you need to? Let us know if it does the trick. ![]() I think that these are about all your options. Based on your most recent quote, it sounds like you want to re-size the rows:įor this I would employ text-wrapping and then autofit the rows. Therefore, going directly to the auto-fit approach, we have two options: either autofit the columns, or autofit the rows. (2) Auto-fit the Column: Dim myRange As Rangeīut if we are going to auto-fit the column, then it is much easier to just call it directly, without checking the column widths first, because not only will the widths be corrected for all cells at one time, but the Range.AutoFit method can handle any font, including non-proportional fonts, in any style. If Len(CStr(cell.Value)) > cell.ColumnWidth Then (1) Set the column width to match the cell's value length: Dim myRange As Range ![]() How will you correct this? If, again, you have a very simple situation where word wrap is not employed and the font is in the Normal style, and, ideally, the Normal font is a non-proportional font, then you have a few options: Next, type the below keys one by one to apply theAutoFit Row Height option. First, select the row having insufficient row height. MsgBox "The cell at " & cell.Address & " has text that is too long!"īut now here comes the next part. If you are a keyboard lover, you can use this method to adjust the row height to fit the text. If column.ColumnWidth cell.ColumnWidth Then To adjust the height of the row to fit all the text in a cell, follow these steps: Select the row you want to adjust the height. Therefore, you might want to create a method that establishes a minimum column width: Sub AutoFitColumns(theRange As Excel.Range, minColumnWidth As Double) If you open this same document in Excel 2013, while having your Display Setting set to 'Medium - 125' - you will notice that all your 'Cell Heights' have been changed. The Range.AutoFit method can be a bit too aggressive, however, resulting in columns that are too narrow. For example, say you have an existing Excel file, created from an earlier version of Excel, and in this document all the 'Cell Heights' are set to '11.25'. ![]() It is much easier to automatically size the columns by making use of the Range.AutoFit method.Īs an example, you can call the AutoFit method as follows: Dim myRange As Excel.Range Identifying which column is too wide would be tricky, especially since the text within the cell can have different fonts and/or font sizes. ![]()
0 Comments
Leave a Reply. |