Results 1 to 2 of 2

Thread: Column Widths (VBA)

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2000
    Posts
    22

    Question

    I have a spreadsheet with A:AA columns, for example, all with varying column widths. What I need to do in code is assign the current column widths to variable, then autofit the columns based on content and print, then be able to revert back to the original column widths. Any ideas? Some sort of array?
    Using VBA

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    If you get hold of a range you can use the ColumnWidth property to set the widths. From Excel VBA help:

    Returns or sets the width of all columns in the specified range. Read/write Variant.

    Remarks

    One unit of column width is equal to the width of one character in the Normal style. For proportional fonts, the width of the character 0 (zero) is used.
    Use the Width property to return the width of a column in points.
    If all columns in the range have the same width, the ColumnWidth property returns the width. If columns in the range have different widths, this property returns Null.
    If you just want to find the widest piece of text then you can loop through the cells checking the length and storing the value if it is the largest you have found so far. I'm not sure how you determine the width of a section of text in a non-fixed-pitch font.
    Harry.

    "From one thing, know ten thousand things."

Posting Permissions

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



Click Here to Expand Forum to Full Width