Adjusting row heights on top of autofit

louisli_evo

New Member
Joined
Mar 11, 2020
Messages
11
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have a table that I need help on making a VBA/macro to adjust row heights on top of autofit-ting, autofit is good but it's too tight in viewing.

Mechanism:
I have a few columns of multi-row texts (B, D, and E), I need to:
- upon content change of that row, for example, I updated row 13 and by the time I hit enter or tab, it should start adjusting.
-- alternatively, I think I can run the VBA on demand, which I think it should be easier
- Range: row 2 to row 309
- if this row contains merged cells, skip to next row
- determine which column (B, D or E) on this row has the most lines
- add 25 pixels to the autofitted height


Could anyone shed some light on this issue? Thank you very much.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
See if this code in the worksheet module does what you need,
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B2:B309,D2:E309")) Is Nothing Then
    With Target
        .EntireRow.AutoFit
        .RowHeight = .RowHeight + 25
    End With
End If
End Sub
The code should autofit, then increase by 25 whenever you make a change to one of the specified cells. I haven't made any allowances for merged cells in the code.
 
Upvote 0
Solution
See if this code in the worksheet module does what you need,
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("B2:B309,D2:E309")) Is Nothing Then
    With Target
        .EntireRow.AutoFit
        .RowHeight = .RowHeight + 25
    End With
End If
End Sub
The code should autofit, then increase by 25 whenever you make a change to one of the specified cells. I haven't made any allowances for merged cells in the code.
 
Upvote 0
Hi Jason,

This is awesome.
I was stuck on how to determine which column has the most lines, without aware that an autofit can be performed in VBA.
Thank you very much.
 
Upvote 0
Is it possible to this for part of the row? I need to change the row height in colums k-z
 
Upvote 0
You can't change the row height of selective columns, it's all or none.
 
Upvote 0
Is it possible to this for part of the row? I need to change the row height in colums k-z
I get what you mean.
Unfortunately this is not how Excel deals with row heights.
The rows are fixed so you can't change the height of some of the columns, but you can manually merge some cells to make it look higher than others.
If you can elaborate on the logic of your idea, it's easier for others to pick up.
 
Upvote 0
but you can manually merge some cells to make it look higher than others.
Which might improve appearance but in many cases, cause bigger problems elsewhere (formulas, vba procedures, etc).
 
Upvote 0
Here is a screen shot:
Excel_IMG.jpg
 
Upvote 0
Here is a screen shot:
I can see 3 replies to your posts so far (4 with this one) telling you that what you want is not possible. Adding a screen capture is not suddenly going to cause a miracle to happen.
 
Upvote 0

Forum statistics

Threads
1,214,909
Messages
6,122,189
Members
449,072
Latest member
DW Draft

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