Fix code request for 'Auto Fit Row Height Of Merged Cells' formula. VBA Excel -


the primary issue macro when text long, height of merged cells becomes large.

the thread on source(listed below), not have satisfying solutions issue.

the merged cell takes info several sources , includes 'char(10) spaces make difficult create single cell column auto-fitting.

option explicit public sub autofitall()   call autofitmergedcells(range("a1:b2"))    call autofitmergedcells(range("c4:d6"))     call autofitmergedcells(range("e1:e3")) end sub  public sub autofitmergedcells(orange range)   dim theight integer   dim iptr integer   dim oldwidth single   dim oldzzwidth single   dim newwidth single   dim newheight single   sheets("sheet4")     oldwidth = 0     iptr = 1 orange.columns.count       oldwidth = oldwidth + .cells(1, orange.column + iptr - 1).columnwidth     next iptr     oldwidth = .cells(1, orange.column).columnwidth + .cells(1, orange.column + 1).columnwidth     orange.mergecells = false     newwidth = len(.cells(orange.row, orange.column).value)     oldzzwidth = .range("zz1").columnwidth     .range("zz1") = left(.cells(orange.row, orange.column).value, newwidth)     .range("zz1").wraptext = true     .columns("zz").columnwidth = oldwidth     .rows("1").entirerow.autofit     newheight = .rows("1").rowheight / orange.rows.count     .rows(cstr(orange.row) & ":" & cstr(orange.row + orange.rows.count - 1)).rowheight = newheight     orange.mergecells = true     orange.wraptext = true     .range("zz1").clearcontents     .range("zz1").columnwidth = oldzzwidth   end end sub 

source: https://www.extendoffice.com/documents/excel/2342-excel-autofit-row-height-merged-cells.html?page_comment=2

try adding line below:

orange.rows(orange.rows.count).entirerow.autofit 

after:

orange.mergecells = true orange.wraptext = true 

in code above


Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -