#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default autofit

I'm trying to get data to fit an excel row. I tried to use the autofit
method, but it si not working. This is my code:

CoverWs.Range("a1").WrapText = True
CoverWs.Range("a1").EntireRow.AutoFit()

Can someone tell me how to fix it?

Thanks in Advance!
~Elena


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default autofit

Do you have merged cells in the row?

if not, it worked OK for me. One thing you can try


Sub AAA()
Set CoverWs = ActiveSheet
With CoverWs.Range("a1")
.WrapText = True
.EntireRow.RowHeight = 409
.EntireRow.AutoFit
End With
End Sub

--
Regards,
Tom Ogilvy


"Elena" wrote:

I'm trying to get data to fit an excel row. I tried to use the autofit
method, but it si not working. This is my code:

CoverWs.Range("a1").WrapText = True
CoverWs.Range("a1").EntireRow.AutoFit()

Can someone tell me how to fix it?

Thanks in Advance!
~Elena


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default autofit

Yes, it is actually a string of merged rows, i was just trying to simplyfy
it... Here's the complete code:

it's in a loop, so "intPrintRow" starts with 5 and then adds one each loop.

Dim strA1 As String = "a" & intPrintRow
Dim strJ1 As String = "j" & intPrintRow
CoverWs.Range(strA1 & ":" & strJ1).Merge()
CoverWs.Range(strA1).Value = strMemo
CoverWs.Range(strA1).Font.Bold = False
CoverWs.Range(strA1).WrapText = True
CoverWs.Range(strA1).EntireRow.AutoFit()

Does the code change for merged cells?

Thanks again,
Elena
"Tom Ogilvy" wrote:

Do you have merged cells in the row?

if not, it worked OK for me. One thing you can try


Sub AAA()
Set CoverWs = ActiveSheet
With CoverWs.Range("a1")
.WrapText = True
.EntireRow.RowHeight = 409
.EntireRow.AutoFit
End With
End Sub

--
Regards,
Tom Ogilvy


"Elena" wrote:

I'm trying to get data to fit an excel row. I tried to use the autofit
method, but it si not working. This is my code:

CoverWs.Range("a1").WrapText = True
CoverWs.Range("a1").EntireRow.AutoFit()

Can someone tell me how to fix it?

Thanks in Advance!
~Elena


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default autofit

Autofit doesn't work with merged cells.

You would have to figure out the row height yourself and set it.

Jim Rech posted some sample code previously which you can use as an example:

Jim Rech

Sub AutoFitMergedCellRowHeight()
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 Sub

--
Regards,
Tom Ogilvy


"Elena" wrote:

Yes, it is actually a string of merged rows, i was just trying to simplyfy
it... Here's the complete code:

it's in a loop, so "intPrintRow" starts with 5 and then adds one each loop.

Dim strA1 As String = "a" & intPrintRow
Dim strJ1 As String = "j" & intPrintRow
CoverWs.Range(strA1 & ":" & strJ1).Merge()
CoverWs.Range(strA1).Value = strMemo
CoverWs.Range(strA1).Font.Bold = False
CoverWs.Range(strA1).WrapText = True
CoverWs.Range(strA1).EntireRow.AutoFit()

Does the code change for merged cells?

Thanks again,
Elena
"Tom Ogilvy" wrote:

Do you have merged cells in the row?

if not, it worked OK for me. One thing you can try


Sub AAA()
Set CoverWs = ActiveSheet
With CoverWs.Range("a1")
.WrapText = True
.EntireRow.RowHeight = 409
.EntireRow.AutoFit
End With
End Sub

--
Regards,
Tom Ogilvy


"Elena" wrote:

I'm trying to get data to fit an excel row. I tried to use the autofit
method, but it si not working. This is my code:

CoverWs.Range("a1").WrapText = True
CoverWs.Range("a1").EntireRow.AutoFit()

Can someone tell me how to fix it?

Thanks in Advance!
~Elena


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 (Columns.EntireColumn.AutoFit) does not work Michiel via OfficeKB.com Excel Discussion (Misc queries) 3 February 10th 09 05:29 PM
autofit does not autofit rreneerob Excel Discussion (Misc queries) 1 October 17th 05 05:55 PM
Autofit kevin Excel Programming 3 October 4th 04 09:26 PM
AutoFit TanahAirShah Excel Programming 1 January 16th 04 10:04 PM
row autofit Robin Hammond Excel Programming 0 September 6th 03 02:33 AM


All times are GMT +1. The time now is 07:26 AM.

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"