Determine necessary height in merged cells to accommodate text that exceeds 409.5

gravanoc

Active Member
Joined
Oct 20, 2015
Messages
348
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I have an issue where a cell may have more text than can be displayed within the maximum row height of 409.5, and due to printing concerns the columns must remain a certain width. In order to accommodate this, I can insert one or more blank rows beneath the row with the target cell, then merge each relevant cell above the new row downward, so I'll have, for instance, A2:A3, B2:B3, C2:C3, etc. as merged entities. The problem is that autofit will not work, and manual adjustment is not a viable solution. The font is Times New Roman and size is always 11 & no other font effects applied. With that being the case, I noticed that at 409.5 a cell can handle about 27.25 lines. My question is how do I tell VBA what the best fit row height will be once the cell is merged?

In this example the merge begins at the dashed line.

BlahBlahBlahBlahBlahBlahBlah
Text Is HereTRUETRUE1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 ----------------- 28 29….FALSEYES
MoreMoreMoreMoreMoreMoreMore
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
it's not that simple, this 'll work in only 99% of the cases, adjust that 14.4 if not okay
VBA Code:
Sub test()
     'preparation
     r = WorksheetFunction.RandBetween(5, 27)                   'random number between 5 and 27
     s = "column(" & Range("A1").Resize(, r).Address & ")"
     a = Join(Evaluate(s), vbLf)                                '---> a sequence 1, 2, 3, .... until r

     'adjust to number of rows
     Range("A1").Resize(, 2).Value = Array(a, r)                'write that sequence and r to the sheet
     i = Len(Range("A1").Value) - Len(Replace(Range("A1").Value, vbLf, "")) + 1     'count the number of linefeeds + 1 = number of rows in that cell
     Range("A1").EntireRow.RowHeight = 14.4 * i                 'the rowheight is 14.4 * i
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,980
Messages
6,122,563
Members
449,088
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top