+ Reply to Thread
Results 1 to 8 of 8

Dynamically adjusting ColumnWidth; only increases- not decreases, based on title Row Width

  1. #1
    Registered User
    Join Date
    01-13-2016
    Location
    Madison, Wi
    MS-Off Ver
    Excel 2013
    Posts
    5

    Dynamically adjusting ColumnWidth; only increases- not decreases, based on title Row Width

    Forgive me if this isn't considered dynamic... it's dynamic...right?

    I couldn't find anything online or in a book that does specifically, what this does. This macro sets a standard column width (for each column) to its current unique setting and not a value- Then compares it to the Autofit column width of the newly pasted in data. If the new data auto fit value is less than the current column width value, then the column will NOT get smaller. The column can only increase in width so that when data upload is complete, the sheet can be read intelligibly.

    I'm open to any comments or feedback on the process I've chosen. I'm sure there's a more elegant method out there- I'm open to all suggestions. I've considered many different ways of tackling this problem but this one seemed to make the most sense to me.

    Hope this helps someone out there.
    Thank you!

    Please Login or Register  to view this content.

  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: Dynamically adjusting ColumnWidth; only increases- not decreases, based on title Row W

    Welcome to the board.

    You want to make all of the columns the width of the widest autofit column?

    Please Login or Register  to view this content.
    Last edited by shg; 05-03-2016 at 10:29 AM.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    01-13-2016
    Location
    Madison, Wi
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: Dynamically adjusting ColumnWidth; only increases- not decreases, based on title Row W

    Thanks for the quick reply and the welcoming response! Glad to be hear- I love this forum!

    To answer your question simply; No. For clarity, please let me explain further. I'm happy with my code; it works beautifully. It's just that I'm in the process of trying to think about writing code more efficiently. That's the second reason why I posted it; the first being that maybe it could help someone with the same problem.

    What I did first was manually fit all the columns to the width that I wanted; each a unique width based on the data/title(text) in my heading row... Row 11. The code above is just a small macro in a larger code that I'm calling after I link a number of workbooks and draw data from each to the rows below it. Sometimes that data is small and when pasted and auto-fitted, reduces the column width to where the heading titles become unintelligible. I didn't want that to happen. So I had to create a macro that would only allow the column width to increase and not decrease after that data was pasted in. What I came up with is above.

    Have I answered your question?

    Just wanted you to know I have so much respect for all you guru's and experts out there. I've seen in a short time how much work it takes to become good at this practice (of writing code). I have a long way to go to reach my 10,000 hours; on my way though.

    Thanks in advance for any feedback!
    Dom

  4. #4
    Registered User
    Join Date
    01-13-2016
    Location
    Madison, Wi
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: Dynamically adjusting ColumnWidth; only increases- not decreases, based on title Row W

    For more clarification: Each column will behave differently based on the data I paste into each column. Some may increase; some may stay the same.

  5. #5
    Registered User
    Join Date
    01-13-2016
    Location
    Madison, Wi
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: Dynamically adjusting ColumnWidth; only increases- not decreases, based on title Row W

    Thanks for the simple code... exactly what I was looking for. I'll play around with it and see how it works.

  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: Dynamically adjusting ColumnWidth; only increases- not decreases, based on title Row W

    Then I would code it like this, to avoid selecting:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-13-2016
    Location
    Madison, Wi
    MS-Off Ver
    Excel 2013
    Posts
    5

    Re: Dynamically adjusting ColumnWidth; only increases- not decreases, based on title Row W

    Thanks for that beauty above; very elegant. Once again, I'll play around and test it a bit. I was trying to implement the UsedRange property but couldn't figure how to use it properly. Now you've shown me.

    Thanks a million. -Dom

  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: Dynamically adjusting ColumnWidth; only increases- not decreases, based on title Row W

    You're welcome.

+ 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. Replies: 4
    Last Post: 03-11-2014, 12:28 AM
  2. Would like to utilize text-to-speech when a cell increases or decreases in value
    By swedum in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-11-2013, 04:56 AM
  3. ColumnWidth vs Column.Width
    By danex in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-24-2013, 10:21 AM
  4. Year-over-year price increases/decreases by region and category
    By psundaram in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 06-20-2013, 11:05 AM
  5. [SOLVED] Add Up/Down Arrows to a Table to increases/decreases in Variances
    By Cortlyn in forum Excel General
    Replies: 2
    Last Post: 05-14-2013, 04:36 PM
  6. counting increases and decreases across rows
    By Northern in forum Excel General
    Replies: 1
    Last Post: 09-25-2010, 09:31 AM
  7. Replies: 5
    Last Post: 02-10-2010, 10:47 AM
  8. increases/decreases from a quote to a booking
    By stasia_laglace in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-31-2008, 12:03 AM

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