+ Reply to Thread
Results 1 to 16 of 16

Need help to auto re-size filtered rows

  1. #1
    Registered User
    Join Date
    07-25-2019
    Location
    hampshire
    MS-Off Ver
    365
    Posts
    15

    Need help to auto re-size filtered rows

    Hi,

    I have a presentation only workbook that draws info from other sources which are dynamic

    i have a VBA code therefore that fires when the workbook is opened to autofit the new data into the row heights.

    The problem that i have is:- if a filter is active when the workbook is opened, the rows in the filtered out cells do not re-size and can potentially hide data when the filter is altered or removed.

    Is there a way of ensuring that the filtered out rows are auto resized when a filter is changed?

    I have tried code that would recognise a change in the workbook but filter changes won't make it fire.

    Thanks in advance

    Mick

  2. #2
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Need help to auto re-size filtered rows

    when you want to adjust the size, this this:

    Worksheets("Sheet1").Range("A1:E1").Columns.AutoFit

    Just make sure to provide the correct range and it will adjust the sizes

    https://docs.microsoft.com/en-us/off....range.autofit example found here


    Also take a look at this site, offers a few other ways to accomplish

    https://excelchamps.com/vba/autofit/
    If you find the suggestion or solution helpful, please consider adding reputation to the post.

  3. #3
    Registered User
    Join Date
    07-25-2019
    Location
    hampshire
    MS-Off Ver
    365
    Posts
    15

    Re: Need help to auto re-size filtered rows

    sorry this doesn't work. it re-sizes everything except cells which have applied filters

  4. #4
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Need help to auto re-size filtered rows

    So if you update the range to something like this it doesnt work?

    Worksheets("Sheet1").Range("A2:Z200").Columns.AutoFit

    Or even this

    ActiveSheet.UsedRange.EntireColumn.AutoFit

    ActiveSheet.UsedRange.EntireRow.AutoFit

  5. #5
    Registered User
    Join Date
    07-25-2019
    Location
    hampshire
    MS-Off Ver
    365
    Posts
    15

    Re: Need help to auto re-size filtered rows

    Sorry no,

    When i open the work book all rows re-size as dictated by the code. However Any row which contains filtered out data does not autofit. When i remove the filter the rows are the same size as when the document was closed. I have tried many times and with many different varieties of the same code but they all ignore filtered cells.

    The only thing i can think of would be to write code to remove all of the filters but then i would have to manually re-apply them all.

    It is quite a complicated set of column data and i could have cross filters applied over 4 or 5 columns so i didn't want to do this if i didn't have to.

    I am aware that i could write data count cells and use VBA to monitor changes in the data count and use that to fire the re-size but this seems quite complicated thing to do for what i see as a simple need.

    What i really need is code that would recognise any filter change on the sheet.

    I have a workaround at the minute. I have a macro which is linked to a form control that i can press every time i alter a filter but every now and again i forget and print the sheet with hidden data.

    It's quite frustrating.

  6. #6
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Need help to auto re-size filtered rows

    Can you provide a sample file that demonstrates these issues?
    Steps can be found up top in the yellow banner.

  7. #7
    Registered User
    Join Date
    07-25-2019
    Location
    hampshire
    MS-Off Ver
    365
    Posts
    15

    Re: Need help to auto re-size filtered rows

    attached is a very basic example of that i am talking about.

    The code is set to re-size the rows in the workbook. when the book is opened it does just that. However row 9 is hidden by a filter which excludes the data within it. As soon as the filter is removed you will see that row 9 has not been re-sized for the data
    Attached Files Attached Files

  8. #8
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Need help to auto re-size filtered rows

    Now i will say, that the autofit looks at all data in the columns and rows even if they are filtered and not seen on the screen.

    So if you have a cell with text like this:
    " Hello, today is Wednesday and its going to be great"

    And then you have in the same column some text like this:
    "Hello"

    And your filtered data is only showing the "Hello", auto fit wont adjust to that smaller size, it will autofit to the larger text.

    If thats what you are experiencing then maybe you will need to get the "size" of the largest cell in the filtered data and set the columnwidth to that value in your results.

  9. #9
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Need help to auto re-size filtered rows

    Are you wanting to keep that "Word Wrap" set on that column or other columns in your workbook?

  10. #10
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Need help to auto re-size filtered rows

    So yea, my post #8 is whats happening with your sample data.
    Even though you have a value in the filtered data that is smaller than the rows that are hidden, the autofit will adjust to the largest in the column regardless if its visible or not.

    So if you want it a certain size you can keep the word wrap and then just set the column width after filtering to a certain size.

  11. #11
    Registered User
    Join Date
    07-25-2019
    Location
    hampshire
    MS-Off Ver
    365
    Posts
    15

    Re: Need help to auto re-size filtered rows

    i need it to auto fit the largest data set and it does this exactly correctly for all rows except those which are filtered out. In reality it doesn't alter the size of the row at all it just ignores it.

  12. #12
    Registered User
    Join Date
    07-25-2019
    Location
    hampshire
    MS-Off Ver
    365
    Posts
    15

    Re: Need help to auto re-size filtered rows

    take a look at the attached example where i have altered the data set. each row re-sizes on opening to fit the contents of the cell. except for the filtered out cell which doesnot re-size
    Attached Files Attached Files

  13. #13
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Need help to auto re-size filtered rows

    Maybe im not understanding clearly, but im trying..

    Is it the rows in green that you are trying get to resize?
    Attached Images Attached Images

  14. #14
    Registered User
    Join Date
    07-25-2019
    Location
    hampshire
    MS-Off Ver
    365
    Posts
    15

    Re: Need help to auto re-size filtered rows

    No,

    in the screen shot you have sent you have cleared the filter because i can see row 9 and the words "sorry this"

    this cell contains much more than these 2 words and if it had been re-sized by the code i would see the words "sorry this doesn't work at all". All the other cells which contain words re-sized to suit their content except row 9 which was hidden by the filter. when you removed the filter it has not resized this row.

    Thanks for your help with this

  15. #15
    Valued Forum Contributor
    Join Date
    05-15-2017
    Location
    US
    MS-Off Ver
    365
    Posts
    901

    Re: Need help to auto re-size filtered rows

    Then im really confused, i just unselected that row and it shows all the words for me, without me manually expanding the cell size. Is that what you need?
    Attached Images Attached Images

  16. #16
    Registered User
    Join Date
    07-25-2019
    Location
    hampshire
    MS-Off Ver
    365
    Posts
    15

    Re: Need help to auto re-size filtered rows

    the first picture you sent is what i see after the code fires showing just the words "sorry this",

    did you save the work book somewhere after opening the filter because then the code would fire on all rows as they would all be visible.

    I have attached a series of pictures on what i am seeing.

    Capture 1
    If you open the workbook on post 12 again you will see all of the rows at the excel default height.
    As soon as you enable content the code fires and the rows are resized

    capture 2
    this shows the rows resized but the row with "sorry this doesn't work at all" is hidden

    Capture 3
    this show what i see when i remove the filter. You can see in this image that the code has not autofit the hidden row.

    if i now saved this workbook and open it again, then yes it would expand this row because it would be no longer hidden
    Attached Images Attached Images

+ 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. [SOLVED] Not correctly counting number of visible rows in auto-filtered table
    By dcwan in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-31-2020, 01:05 PM
  2. [SOLVED] Google Sheets: Can't build box size matrix to work with formula to auto select box size
    By DendetheNameknoob in forum For Other Platforms(Mac, Google Docs, Mobile OS etc)
    Replies: 3
    Last Post: 07-15-2020, 08:20 AM
  3. Can't build box size matrix to work with formula to auto select box size
    By DendetheNameknoob in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-10-2020, 07:04 AM
  4. Cell reference to filtered data auto update as Filtered result changes
    By Irajoo in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-22-2017, 02:17 AM
  5. Using auto-size with forms - need to size based on text!
    By AnnaG87 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-04-2014, 11:51 AM
  6. Replies: 4
    Last Post: 08-16-2012, 06:20 PM
  7. Auto adjust rows to size of contents
    By Howjos in forum Excel General
    Replies: 6
    Last Post: 07-04-2006, 12:20 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