Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default define cell for autofit of merged cells

Hello,
I've got Jim Rech's sub for autofit of merged cells,
http://www.google.com/groups?threadm=uGMQVjd0CHA.2296%
40TK2MSFTNGP10

I want to use sub to adjust row 16 before print. I've
put it in the ThisWorkbook object. My problem is defining
row 16. I've tried...

1) defining CurrCell with
Set CurrCell = Worksheets("Sheet1").Range("A16:H16")

2) using
With Range ("A16:H16")
instead of
If ActiveCell.MergeCells Then
With ActiveCell.MergeArea

3) both of the above with ("A16") instead of ("A16:H16")

4) generally butchering a perfectly good working sub in
multiple ways :-)

A simple fix I'm sure, but I'm stumped.

Thanks in advance!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default define cell for autofit of merged cells

Does row 16 contain merged cells?

If so, are there multiple merged areas or only one merged area (A16:H16 for
example).

--
Regards,
Tom Ogilvy

"erin" <espencer@wdprosdotcom wrote in message
...
Hello,
I've got Jim Rech's sub for autofit of merged cells,
http://www.google.com/groups?threadm=uGMQVjd0CHA.2296%
40TK2MSFTNGP10

I want to use sub to adjust row 16 before print. I've
put it in the ThisWorkbook object. My problem is defining
row 16. I've tried...

1) defining CurrCell with
Set CurrCell = Worksheets("Sheet1").Range("A16:H16")

2) using
With Range ("A16:H16")
instead of
If ActiveCell.MergeCells Then
With ActiveCell.MergeArea

3) both of the above with ("A16") instead of ("A16:H16")

4) generally butchering a perfectly good working sub in
multiple ways :-)

A simple fix I'm sure, but I'm stumped.

Thanks in advance!




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default define cell for autofit of merged cells

Row 16 has only 1 merged area, A16:H16.

-----Original Message-----
Does row 16 contain merged cells?

If so, are there multiple merged areas or only one

merged area (A16:H16 for
example).

--
Regards,
Tom Ogilvy

"erin" <espencer@wdprosdotcom wrote in message
...
Hello,
I've got Jim Rech's sub for autofit of merged cells,
http://www.google.com/groups?threadm=uGMQVjd0CHA.2296%
40TK2MSFTNGP10

I want to use sub to adjust row 16 before print. I've
put it in the ThisWorkbook object. My problem is

defining
row 16. I've tried...

1) defining CurrCell with
Set CurrCell = Worksheets("Sheet1").Range("A16:H16")

2) using
With Range ("A16:H16")
instead of
If ActiveCell.MergeCells Then
With ActiveCell.MergeArea

3) both of the above with ("A16") instead of

("A16:H16")

4) generally butchering a perfectly good working sub in
multiple ways :-)

A simple fix I'm sure, but I'm stumped.

Thanks in advance!




.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default define cell for autofit of merged cells

The easiest solution would be

Sub AutoFitMergedCellRowHeight()
Dim CurrentRowHeight As Single, MergedCellRgWidth As Single
Dim CurrCell As Range, rngActive as Range
Dim ActiveCellWidth As Single, PossNewRowHeight As Single
set rngActive = selection
Range("A16").Select
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
rngActive.Select
End Sub

--
Regards,
Tom Ogilvy


"erin" <espencer@wdprosdotcom wrote in message
...
Row 16 has only 1 merged area, A16:H16.

-----Original Message-----
Does row 16 contain merged cells?

If so, are there multiple merged areas or only one

merged area (A16:H16 for
example).

--
Regards,
Tom Ogilvy

"erin" <espencer@wdprosdotcom wrote in message
...
Hello,
I've got Jim Rech's sub for autofit of merged cells,
http://www.google.com/groups?threadm=uGMQVjd0CHA.2296%
40TK2MSFTNGP10

I want to use sub to adjust row 16 before print. I've
put it in the ThisWorkbook object. My problem is

defining
row 16. I've tried...

1) defining CurrCell with
Set CurrCell = Worksheets("Sheet1").Range("A16:H16")

2) using
With Range ("A16:H16")
instead of
If ActiveCell.MergeCells Then
With ActiveCell.MergeArea

3) both of the above with ("A16") instead of

("A16:H16")

4) generally butchering a perfectly good working sub in
multiple ways :-)

A simple fix I'm sure, but I'm stumped.

Thanks in advance!




.



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
Autofit Merged cell Code is changing the format of my merged cells JB Excel Discussion (Misc queries) 0 August 20th 07 02:12 PM
Is there a way to Autofit Merged Cells in a row? JLSmith Excel Discussion (Misc queries) 2 August 1st 06 04:49 PM
Row Autofit on Merged Cells Jluo Excel Discussion (Misc queries) 1 April 18th 05 02:37 PM
Autofit Merged Cells in Excel kchambers Excel Discussion (Misc queries) 6 March 5th 05 04:57 PM
Autofit in Merged Cells? Mick Excel Discussion (Misc queries) 4 February 14th 05 05:15 PM


All times are GMT +1. The time now is 11:58 PM.

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

About Us

"It's about Microsoft Excel"