+ Reply to Thread
Results 1 to 7 of 7

Setting column width in VBA - easy, right?

  1. #1
    Registered User
    Join Date
    07-09-2012
    Location
    Pittsburgh, PA USA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Setting column width in VBA - easy, right?

    I feel really stupid. I can't set the column width.

    The following code /should/ shrink the page widths by a factor of two, roughly. Instead, it stops with an error on the col.Width line:
    Object required.

    Please Login or Register  to view this content.
    What INCREDIBLY OBVIOUS thing am I missing?

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Setting column width in VBA - easy, right?

    Please Login or Register  to view this content.

  3. #3
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Setting column width in VBA - easy, right?

    it's a very misleading error! ;-)
    the width property is read-only-you need to set the columnwidth property (to 8.43)
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Setting column width in VBA - easy, right?

    Please Login or Register  to view this content.
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Setting column width in VBA - easy, right?

    No need to loop through all columns.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-09-2012
    Location
    Pittsburgh, PA USA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Setting column width in VBA - easy, right?

    Oh, FFS... thanks, all. And thanks to jindon for the extra note; I looked for that under Worksheet objects, not Columns objects.

  7. #7
    Registered User
    Join Date
    07-09-2012
    Location
    Pittsburgh, PA USA
    MS-Off Ver
    Excel 2007
    Posts
    13

    Re: Setting column width in VBA - easy, right?

    No need to loop through all columns.
    Actually, jindan, your method only works if every column is the same width. Glad I caught that before running it, because mine aren't.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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