locked
VBA autofit row height when columns are merged - why sometimes not working ? RRS feed

  • Question

  • I came across very strange behaviour. I have this peace of VBA code which adjusts height of some rows in my sheet depending on amount of text. The code is simple (uses names for ranges):

        Range("cel_biznesowy").EntireRow.AutoFit
        Range("nazwa_proj").EntireRow.AutoFit
        Range("uzasadnienie").EntireRow.AutoFit
        Range("zakres").EntireRow.AutoFit
        Range("jakoscio").EntireRow.AutoFit
        Range("main_risk").EntireRow.AutoFit

    It works for 4 first lines and doesn't work for two last although the formatting of rows is the same. The range of all names is the same (only worksheet).

    What is strange that also when I try to adjust those last two rows manualy - by clicking the row header between rows.

    What can be the reason of such strange behaviour ? I am running out of ideas :/

    Tuesday, January 7, 2014 3:45 PM

All replies

  • Do the "problem" rows contain merged cells? Excel can't autofit rows that contain merged cells.

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Tuesday, January 7, 2014 9:40 PM
  • But it works for merged cells. I have those 6 rows with merged cells and auto-fit works for them but what observed today - the auto-fit works only within boundaries of one page: for example if I enter some text to first row - auto-fit works great but when I put some text to second row that would make the row height beyond one page the auto-fit works only partially...This is all crazy :/
    Friday, January 10, 2014 10:52 AM