Hi all,
Yesterday I asked a question if, and how, I can adjust the width of multiple columns to their contents, and then add just a little more width for easier readability.
The code Ollie came up with (thanks again Ollie !) was:
This works fine, with 1 exception. If, in a large spreadsheet, i start eg in a name column and that name is shorter than the other entries, the new width of the column is relative to this smaller cell.![]()
Public Sub AutoFitPlus() '# '# declare private variables '# Dim xlsColumn As Excel.Range Const clngMargin As Long = 5 '# '# set columns in selection to autofit '# Selection.Columns.AutoFit '# '# add a small margin the the column width for all columns '# within the selection '# For Each xlsColumn In Selection.Columns xlsColumn.ColumnWidth = xlsColumn.ColumnWidth + clngMargin Next xlsColumn End Sub
When I doubble click between the columns (even if I am in the same (short) cell, the column is adjusted to the longest cell in that column.
Is it possible to add this to the code mentioned above?
Thanks Hein
Bookmarks