Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Auto Re-Sizing Merged Cells

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Auto Re-Sizing Merged Cells

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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
trying to sort excel data. won't allow. merged cells sizing.?? Skinny in the footlhills Excel Discussion (Misc queries) 1 May 25th 09 03:42 PM
Automatically re-sizing merged cells LongTermNoob Excel Worksheet Functions 1 March 28th 07 10:42 AM
Auto fit in merged cells LDF Excel Programming 4 December 20th 05 06:39 PM
How do I auto fit when the cells are merged together? Christa Excel Worksheet Functions 1 November 1st 05 05:35 PM
Auto fit merged cells Anson Excel Discussion (Misc queries) 1 December 20th 04 09:09 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"