Using .EntireRow.AutoFit

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Using .EntireRow.AutoFit

Post by ABabeNChrist »

I’m using

Code: Select all

    With Target
        .WrapText = True
        If .RowHeight < 21.5 Then
            .RowHeight = 21.5
        Else
            .EntireRow.AutoFit
        End If
    End With
With Worksheet_Change. It works great, except I’m trying to keep 4 different rows from being affected.

User avatar
HansV
Administrator
Posts: 78524
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Using .EntireRow.AutoFit

Post by HansV »

Change the code as follows, and modify the list of exceptions as needed:

Code: Select all

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    For Each rng In Target.Rows
        Select Case rng.Row
            Case 1, 4, 12, 37 ' Rows that will be skipped
                ' Do nothing
            Case Else
                With rng
                    .WrapText = True
                    If .RowHeight < 21.5 Then
                        .RowHeight = 21.5
                    Else
                        .EntireRow.AutoFit
                    End If
                End With
        End Select
    Next rng
End Sub
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Using .EntireRow.AutoFit

Post by ABabeNChrist »

Thank you Hans
This has also helps me have a little more understanding how to use for each range in the target rows.