Excel - Row widths & merged cells

krehkop

Board Regular
Joined
Jul 6, 2007
Messages
133
Office Version
  1. 365
Platform
  1. Windows
I have 3 cells (in columns a,b & c) that are merged. Text is entered into this merged cell. Why can't I highlight the row, double click one of the lines above or below the row number and have the row automatically format correctly to a width that shows all text? If I center across selection instead of merging this will work, however, the format is wrong b/c everything's centered.

Does anyone know why this is or a better way?

Thanks!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
I don't think there is any way to "automatically" do this but it can be done with code.

It entails unmerging the cells, doing an autoheight or autowidth, getting the width or height of the single cell, re-merging the cells then setting the width or height based on what the unmerged cell autosized to.
 
Upvote 0
Thanks Ken, I will play around w/ a macro based on that info...
 
Upvote 0
I mis-stated the solution.


get the full width of the merged range
un merge the cells
set the single cell width to what the merged width was
autosize the row
return the first cell width to it's original width
re-merge the cells


It sounds pretty easy but there may be issues with pixels, points and characters.
 
Upvote 0
Try this

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim PartialWidth As Long
Dim FullWidth As Long
Dim CellCount As Long
Dim X As Long
Dim NewHeight As Long


'Copying and pasting causes an error trying to retrieve the merge area
If Application.CutCopyMode Then Exit Sub


    If Target.MergeCells Then
        PartialWidth = Target.MergeArea.Cells(1).ColumnWidth
        CellCount = Target.MergeArea.Cells.Count
        For X = 1 To CellCount
            FullWidth = FullWidth + Target.MergeArea.Cells(1, X).ColumnWidth
   
        Next
        Target.MergeCells = False
        Target.EntireColumn.ColumnWidth = FullWidth
        Target.EntireRow.AutoFit
        NewHeight = Target.RowHeight
        Target.ColumnWidth = PartialWidth
        Target.Resize(, CellCount).MergeCells = True
        Target.EntireRow.RowHeight = NewHeight
    End If
    

End Sub
 
Upvote 0
Thanks Ken and Oaktree...excellent!

Oaktree, Barry Katcher's picture gave me a good laugh this morning...I needed that! :)
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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