+ Reply to Thread
Results 1 to 9 of 9

In VBA, how to set col widths for (say) 7 cols to fit sheet width any screen resolution?

  1. #1
    Registered User
    Join Date
    09-02-2019
    Location
    Honiton, England
    MS-Off Ver
    2016
    Posts
    5

    In VBA, how to set col widths for (say) 7 cols to fit sheet width any screen resolution?

    In VBA, I have several sheets with different numbers of columns. I want to set different widths on these columns within a sheet, but they should all exactly fit the sheet width so the user does not have to scroll horizontally. This should work for any screen resolution. Any ideas?

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: In VBA, how to set col widths for (say) 7 cols to fit sheet width any screen resolutio

    You could autofit the column widths, select any row of the data, and then zoom to selection. Does that give the desired result?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: In VBA, how to set col widths for (say) 7 cols to fit sheet width any screen resolutio

    Please Login or Register  to view this content.
    would give you 7 equally spaced columns. But if you want different columns to be different widths then you would have to do some math to figure out what to divide the UsableWidth constant by.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  4. #4
    Registered User
    Join Date
    09-02-2019
    Location
    Honiton, England
    MS-Off Ver
    2016
    Posts
    5

    Re: In VBA, how to set col widths for (say) 7 cols to fit sheet width any screen resolutio

    Thanks SHG. Unfortunately, the Zoom expands the vertical dimensions (row height) and text size, which I did not want. But the autofit may work if I can set one column width independently. I need to check.

  5. #5
    Registered User
    Join Date
    09-02-2019
    Location
    Honiton, England
    MS-Off Ver
    2016
    Posts
    5

    Re: In VBA, how to set col widths for (say) 7 cols to fit sheet width any screen resolutio

    Many thanks JLGWhiz. I think UsableWidth will do the trick.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: In VBA, how to set col widths for (say) 7 cols to fit sheet width any screen resolutio

    Except it's in pixels, and column widths are not ...

  7. #7
    Registered User
    Join Date
    09-02-2019
    Location
    Honiton, England
    MS-Off Ver
    2016
    Posts
    5

    Re: In VBA, how to set col widths for (say) 7 cols to fit sheet width any screen resolutio

    Yes, SHG, when I tried UsableWidth, my columns were many times too wide.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: In VBA, how to set col widths for (say) 7 cols to fit sheet width any screen resolutio

    If they are all to be the same width,

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    09-02-2019
    Location
    Honiton, England
    MS-Off Ver
    2016
    Posts
    5

    Re: In VBA, how to set col widths for (say) 7 cols to fit sheet width any screen resolutio

    Thanks SHG. On my computer your solution shows a bit of column H as well, but users can manually adjust it out of sight. I will use this method. My original method was diabolically complex, which meant it was *probably* incorrect, and it showed a teensy bit of col H too, which meant it was *definitely* incorrect. The other thing I could do would be to simply set the various ColumnWidths individually to the max expected for that field, and apply word-wrap to text columns like Memo or Description, where the number of chars is unpredictable.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Help with VBA Autofit Screen View to any screen resolution
    By Jalica in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-04-2018, 04:10 AM
  2. Application.Width = 75% of Stated Screen Resolution. What is causing this?
    By SymphonyTomorrow in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-30-2014, 01:38 PM
  3. [SOLVED] Adjust screen resolution automatically to fit all screen sizes
    By Ace_XL in forum Excel General
    Replies: 2
    Last Post: 06-14-2012, 08:51 AM
  4. Screen Resolution
    By yonyon7 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-22-2007, 12:39 PM
  5. [SOLVED] Can't get screen resolution
    By StevenS in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-12-2005, 09:10 AM
  6. [SOLVED] sheet tabs are gone (screen resolution)
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-10-2005, 01:06 PM
  7. [SOLVED] Screen Resolution
    By Ronbo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-17-2005, 10:06 PM

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