Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
LDF LDF is offline
external usenet poster
 
Posts: 1
Default Auto fit in merged cells

I am trying to paste in the code to ensure the merged cells in my spreadsheet
autofit the text that is written.
I have followed previous queries on the subject, and used the code provided.
Never having attempted this before, of course it isn't working and I don't
know why.
Any help would be appreciated
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Auto fit in merged cells

Hi LDF,

See David McRitchie's 'Getting Started With Macros And User Defined
Functions' at:

http://www.mvps.org/dmcritchie/excel/getstarted.htm



---
Regards,
Norman


"LDF" wrote in message
...
I am trying to paste in the code to ensure the merged cells in my
spreadsheet
autofit the text that is written.
I have followed previous queries on the subject, and used the code
provided.
Never having attempted this before, of course it isn't working and I don't
know why.
Any help would be appreciated



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Auto fit in merged cells

Perhaps this isn't your problem, but just to be su
Assuming you are using Jim Rech's code, you have to run the code for it to
do anything. Just putting it in a module does not cause it to autofit
merged cells.

Also, this line
If .Rows.Count = 1 And .WrapText = True Then
tells you that it only works for single row, multiple column merged cells
(with WrapText set to true)

--
regards,
Tom Ogilvy



"LDF" wrote in message
...
I am trying to paste in the code to ensure the merged cells in my

spreadsheet
autofit the text that is written.
I have followed previous queries on the subject, and used the code

provided.
Never having attempted this before, of course it isn't working and I don't
know why.
Any help would be appreciated



  #4   Report Post  
Posted to microsoft.public.excel.programming
Joe Joe is offline
external usenet poster
 
Posts: 476
Default Auto fit in merged cells

Is there any reason why this code would work fine in Excel 2003 but not in
Excel 2000?

Thanks very much,
Joe

Dim OldRng As Range ' DECLARED THIS AT TOP OF MODULE

Private Sub Worksheet_Change(ByVal Target As Range)
Dim NewRwHt As Single
Dim cWdth As Single, MrgeWdth As Single
Dim c As Range, cc As Range
Dim ma As Range
Dim Protected As Boolean

If Target.Column = 1 And (Target.Row 16 And Target.Row < 42) Then
Cells(Target.Row, 2).Select
End If
Protected = False
Set c = Cells(Target.Row, 1)
If OldRng Is Nothing Then Set OldRng = c
If Not Intersect(OldRng, c) Is Nothing Then
Application.ScreenUpdating = True
If Me.ProtectContents Then
Protected = True
Me.Unprotect
End If
cWdth = c.ColumnWidth
Set ma = c.MergeArea
For Each cc In ma.Cells
MrgeWdth = MrgeWdth + cc.ColumnWidth
Next
ma.MergeCells = False
c.ColumnWidth = MrgeWdth
c.EntireRow.AutoFit
NewRwHt = c.RowHeight
c.ColumnWidth = cWdth
ma.MergeCells = True
ma.RowHeight = NewRwHt
cWdth = 0: MrgeWdth = 0
ma.Locked = False
If Protected Then Me.Protect
Application.ScreenUpdating = True
End If
Set OldRng = Target
Set c = Nothing
Set OldRng = Nothing
End Sub

"Tom Ogilvy" wrote:

Perhaps this isn't your problem, but just to be su
Assuming you are using Jim Rech's code, you have to run the code for it to
do anything. Just putting it in a module does not cause it to autofit
merged cells.

Also, this line
If .Rows.Count = 1 And .WrapText = True Then
tells you that it only works for single row, multiple column merged cells
(with WrapText set to true)

--
regards,
Tom Ogilvy



"LDF" wrote in message
...
I am trying to paste in the code to ensure the merged cells in my

spreadsheet
autofit the text that is written.
I have followed previous queries on the subject, and used the code

provided.
Never having attempted this before, of course it isn't working and I don't
know why.
Any help would be appreciated




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Auto fit in merged cells

It was originally written in the xl97/xl2000 timeframe, so I don't see any
reason it would not work in all versions after xl95 (merged cells were
introduced in xl97).

--
Regards,
Tom Ogilvy


"Joe" wrote in message
...
Is there any reason why this code would work fine in Excel 2003 but not in
Excel 2000?

Thanks very much,
Joe

Dim OldRng As Range ' DECLARED THIS AT TOP OF MODULE

Private Sub Worksheet_Change(ByVal Target As Range)
Dim NewRwHt As Single
Dim cWdth As Single, MrgeWdth As Single
Dim c As Range, cc As Range
Dim ma As Range
Dim Protected As Boolean

If Target.Column = 1 And (Target.Row 16 And Target.Row < 42) Then
Cells(Target.Row, 2).Select
End If
Protected = False
Set c = Cells(Target.Row, 1)
If OldRng Is Nothing Then Set OldRng = c
If Not Intersect(OldRng, c) Is Nothing Then
Application.ScreenUpdating = True
If Me.ProtectContents Then
Protected = True
Me.Unprotect
End If
cWdth = c.ColumnWidth
Set ma = c.MergeArea
For Each cc In ma.Cells
MrgeWdth = MrgeWdth + cc.ColumnWidth
Next
ma.MergeCells = False
c.ColumnWidth = MrgeWdth
c.EntireRow.AutoFit
NewRwHt = c.RowHeight
c.ColumnWidth = cWdth
ma.MergeCells = True
ma.RowHeight = NewRwHt
cWdth = 0: MrgeWdth = 0
ma.Locked = False
If Protected Then Me.Protect
Application.ScreenUpdating = True
End If
Set OldRng = Target
Set c = Nothing
Set OldRng = Nothing
End Sub

"Tom Ogilvy" wrote:

Perhaps this isn't your problem, but just to be su
Assuming you are using Jim Rech's code, you have to run the code for it

to
do anything. Just putting it in a module does not cause it to autofit
merged cells.

Also, this line
If .Rows.Count = 1 And .WrapText = True Then
tells you that it only works for single row, multiple column merged

cells
(with WrapText set to true)

--
regards,
Tom Ogilvy



"LDF" wrote in message
...
I am trying to paste in the code to ensure the merged cells in my

spreadsheet
autofit the text that is written.
I have followed previous queries on the subject, and used the code

provided.
Never having attempted this before, of course it isn't working and I

don't
know why.
Any help would be appreciated






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
Auto Filter and Merged Cells AlisonMP2 Excel Worksheet Functions 2 December 5th 07 12:57 AM
How do I auto fit when the cells are merged together? Christa Excel Worksheet Functions 1 November 1st 05 05:35 PM
Auto Row Height for Merged Cells Jamie Excel Programming 13 July 1st 05 12:55 AM
Auto fit wrapped and merged cells elmo2 Excel Discussion (Misc queries) 1 January 17th 05 06:45 AM
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 06:48 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"