Merged into a corner

fullxtension

New Member
Joined
Jun 12, 2006
Messages
1
Ok, I'm new...but I've been playing around with Excel and making it do things it wasn't supposed to do for years. However, I'm not too proud to admit it when I'm stumped.

This has to be one of the standard Excel challenges of lore...I have four cells in the same row merged together. There is text that is randomly assigned to this space that may or may not take more than one row to display. I'm trying to write a macro that will automatically adjust the row height to fit the text once it is determined. It seems that you cannot auto adjust the height of merged cells (even if they are all the same size as the error message insists). Help me out please. Can this be done without a sledge hammer?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try using "Center Across Selection” instead of using Merging.
How?
Select Cells you want to Center. IE: Select C5:C8
Right Click (or Ctrl-1) and bring up Format Cells Menu
Click Alignment Tab
Under Horizontal Alignment, choose “Center Across Selection” from dropdown menu
Click OK to complete.
This will allow the same features as “Merging” without the nuisance of that type of Formating.
You will still be able to edit each Cell/Column separately.
 
Upvote 0
H, fullxtension
Welcome to the Board !!!!!

if you really have no choice
Code:
Option Explicit

Sub fit_height_merged_cells()
'Erik Van Get
'060612
'use only if "center accross selection" is really not an option

Dim rng As Range
Dim MergeArea As Range
Dim FC As Integer
Dim LC As Integer
Dim FCWidth
Dim TotalWidth As Double
Dim i As Integer

Set rng = Selection
Set MergeArea = rng(1).MergeArea

    If MergeArea.Address <> rng.Address Or rng.Cells.Count = 1 Then
    MsgBox "Please select one MergeArea", 48, "ERROR"
    Exit Sub
    End If

FC = MergeArea.Column
LC = FC + MergeArea.Columns.Count - 1

FCWidth = Columns(FC).ColumnWidth
    
    For i = FC To LC
    TotalWidth = TotalWidth + Columns(i).ColumnWidth
    Next i

Application.ScreenUpdating = False
    rng.UnMerge
    rng(1).ColumnWidth = TotalWidth
    rng(1).EntireRow.AutoFit
    rng.Merge
    Columns(FC).ColumnWidth = FCWidth
Application.ScreenUpdating = True

End Sub
kind regards,
Erik
 
Upvote 0

Forum statistics

Threads
1,214,872
Messages
6,122,026
Members
449,061
Latest member
TheRealJoaquin

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