+ Reply to Thread
Results 1 to 4 of 4

autofit

Hybrid View

  1. #1
    Elena
    Guest

    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. #2
    Tom Ogilvy
    Guest

    RE: 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. #3
    Elena
    Guest

    RE: 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. #4
    Tom Ogilvy
    Guest

    RE: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1