Results 1 to 3 of 3

column width, differences between methods

Threaded View

  1. #1
    Forum Contributor
    Join Date
    06-29-2005
    Posts
    201

    column width, differences between methods

    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:
    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
    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.
    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
    Last edited by Hein; 01-10-2013 at 07:50 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1