PC Review


Reply
Thread Tools Rate Thread

Auto Re-Sizing Merged Cells

 
 
=?Utf-8?B?TG9uZ1Rlcm1Ob29i?=
Guest
Posts: n/a
 
      28th Mar 2007
I have created a workbook with one sheet for inputting information, and
several other sheets containing the printed forms required for this job.

Some of these cells contain text, and the amount entered varies dramatically
from project to project. I therefor need to auto size the rows involved - and
have to use a macro as they are merged cells. The macro is run using the
change_worksheet private macro and is shown below. It works well for
individual cells, but I would like it to run on the corresponding cells in
the other worksheets when the cell on the input sheet is altered.

Any siggestions gratefully received.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Intersect(Target, Range("E12:R12")) Is Nothing Then
Exit Sub
Else
Range("E12:R12").Select
Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
Dim CurrCell As Range
Dim ActiveCellWidth As Single, PossNewRowHeight As Single
If ActiveCell.MergeCells Then
With ActiveCell.MergeArea
If .Rows.Count = 1 And .WrapText = True Then
Application.ScreenUpdating = False
CurrentRowHeight = .RowHeight
ActiveCellWidth = ActiveCell.ColumnWidth
For Each CurrCell In Selection
MergedCellRgWidth = CurrCell.ColumnWidth + _
MergedCellRgWidth
Next
.MergeCells = False
.Cells(1).ColumnWidth = MergedCellRgWidth
.EntireRow.AutoFit
PossNewRowHeight = .RowHeight
.Cells(1).ColumnWidth = ActiveCellWidth
.MergeCells = True
.RowHeight = IIf(CurrentRowHeight > PossNewRowHeight, _
CurrentRowHeight, PossNewRowHeight)
End If
End With
End If
End If
End Sub
 
Reply With Quote
 
 
 
 
=?Utf-8?B?TG9uZ1Rlcm1Ob29i?=
Guest
Posts: n/a
 
      28th Mar 2007
The first line of the macro should read:

Private Sub Worksheet_Change(ByVal Target As Range)

I pasted a copy of a previous, failed, macro!!

"LongTermNoob" wrote:

> I have created a workbook with one sheet for inputting information, and
> several other sheets containing the printed forms required for this job.
>
> Some of these cells contain text, and the amount entered varies dramatically
> from project to project. I therefor need to auto size the rows involved - and
> have to use a macro as they are merged cells. The macro is run using the
> change_worksheet private macro and is shown below. It works well for
> individual cells, but I would like it to run on the corresponding cells in
> the other worksheets when the cell on the input sheet is altered.
>
> Any siggestions gratefully received.
>
>
> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> If Intersect(Target, Range("E12:R12")) Is Nothing Then
> Exit Sub
> Else
> Range("E12:R12").Select
> Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
> Dim CurrCell As Range
> Dim ActiveCellWidth As Single, PossNewRowHeight As Single
> If ActiveCell.MergeCells Then
> With ActiveCell.MergeArea
> If .Rows.Count = 1 And .WrapText = True Then
> Application.ScreenUpdating = False
> CurrentRowHeight = .RowHeight
> ActiveCellWidth = ActiveCell.ColumnWidth
> For Each CurrCell In Selection
> MergedCellRgWidth = CurrCell.ColumnWidth + _
> MergedCellRgWidth
> Next
> .MergeCells = False
> .Cells(1).ColumnWidth = MergedCellRgWidth
> .EntireRow.AutoFit
> PossNewRowHeight = .RowHeight
> .Cells(1).ColumnWidth = ActiveCellWidth
> .MergeCells = True
> .RowHeight = IIf(CurrentRowHeight > PossNewRowHeight, _
> CurrentRowHeight, PossNewRowHeight)
> End If
> End With
> End If
> End If
> End Sub

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
trying to sort excel data. won't allow. merged cells sizing.?? Skinny in the footlhills Microsoft Excel Misc 2 25th May 2009 03:42 PM
trying to sort excel data. won't allow. merged cells sizing.?? Skinny in the footlhills Microsoft Excel Misc 0 25th May 2009 03:36 PM
Automatically re-sizing merged cells =?Utf-8?B?TG9uZ1Rlcm1Ob29i?= Microsoft Excel Worksheet Functions 1 28th Mar 2007 10:42 AM
How do I auto fit when the cells are merged together? =?Utf-8?B?Q2hyaXN0YQ==?= Microsoft Excel Worksheet Functions 1 1st Nov 2005 05:35 PM
Auto fit merged cells =?Utf-8?B?QW5zb24=?= Microsoft Excel Misc 1 20th Dec 2004 09:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:02 AM.