+ Reply to Thread
Results 1 to 8 of 8

autofit row code

  1. #1
    Randy Starkey
    Guest

    autofit row code

    I would like to look at all rows in an active sheet (from row 3 down) and
    then autofit the rows. I'd like to add this to my sort macro.

    Here's what I've got...

    Sub Hospital_Sheet_Sort()
    Dim myRng As Range

    With ActiveSheet
    Set myRng = .Range("A3:V" & .Cells(.Rows.Count, "A").End(xlUp).Row)
    myRng.Sort Key1:=Range("A3"), Order1:=xlAscending, Key2:=Range("N3") _
    , Order2:=xlDescending, Header:=xlNo, OrderCustom:=1,
    MatchCase:=False _
    , Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
    DataOption2:= _
    xlSortNormal
    End With
    myRng.AutoFit.Row
    Range("A3:A3").Select
    End Sub

    I get an error on the myRng autofitting.
    I'm doing something wrong obviously...
    Any help would be appreciated.

    Thanks!

    --Randy Starkey



  2. #2
    Nick Hodge
    Guest

    Re: autofit row code

    Randy

    I suppose it doesn't matter if you autofit *all* rows (inc 1-3?)

    You could then simply put above the End With statement

    ..Rows.AutoFit

    If you then need to set back the top three you could do that with

    ..Rows("1:3").RowHeight = 12

    --
    HTH
    Nick Hodge
    Microsoft MVP - Excel
    Southampton, England
    [email protected]HIS


    "Randy Starkey" <[email protected]> wrote in
    message news:[email protected]...
    >I would like to look at all rows in an active sheet (from row 3 down) and
    >then autofit the rows. I'd like to add this to my sort macro.
    >
    > Here's what I've got...
    >
    > Sub Hospital_Sheet_Sort()
    > Dim myRng As Range
    >
    > With ActiveSheet
    > Set myRng = .Range("A3:V" & .Cells(.Rows.Count, "A").End(xlUp).Row)
    > myRng.Sort Key1:=Range("A3"), Order1:=xlAscending, Key2:=Range("N3") _
    > , Order2:=xlDescending, Header:=xlNo, OrderCustom:=1,
    > MatchCase:=False _
    > , Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
    > DataOption2:= _
    > xlSortNormal
    > End With
    > myRng.AutoFit.Row
    > Range("A3:A3").Select
    > End Sub
    >
    > I get an error on the myRng autofitting.
    > I'm doing something wrong obviously...
    > Any help would be appreciated.
    >
    > Thanks!
    >
    > --Randy Starkey
    >




  3. #3
    Randy Starkey
    Guest

    Re: autofit row code

    Nick,

    Can I do...

    ..Rows("1:3").AutoFit

    Thanks!

    --Randy


    "Nick Hodge" <[email protected]> wrote in message
    news:%[email protected]...
    > Randy
    >
    > I suppose it doesn't matter if you autofit *all* rows (inc 1-3?)
    >
    > You could then simply put above the End With statement
    >
    > .Rows.AutoFit
    >
    > If you then need to set back the top three you could do that with
    >
    > .Rows("1:3").RowHeight = 12
    >
    > --
    > HTH
    > Nick Hodge
    > Microsoft MVP - Excel
    > Southampton, England
    > [email protected]HIS
    >
    >
    > "Randy Starkey" <[email protected]> wrote in
    > message news:[email protected]...
    >>I would like to look at all rows in an active sheet (from row 3 down) and
    >>then autofit the rows. I'd like to add this to my sort macro.
    >>
    >> Here's what I've got...
    >>
    >> Sub Hospital_Sheet_Sort()
    >> Dim myRng As Range
    >>
    >> With ActiveSheet
    >> Set myRng = .Range("A3:V" & .Cells(.Rows.Count, "A").End(xlUp).Row)
    >> myRng.Sort Key1:=Range("A3"), Order1:=xlAscending, Key2:=Range("N3") _
    >> , Order2:=xlDescending, Header:=xlNo, OrderCustom:=1,
    >> MatchCase:=False _
    >> , Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
    >> DataOption2:= _
    >> xlSortNormal
    >> End With
    >> myRng.AutoFit.Row
    >> Range("A3:A3").Select
    >> End Sub
    >>
    >> I get an error on the myRng autofitting.
    >> I'm doing something wrong obviously...
    >> Any help would be appreciated.
    >>
    >> Thanks!
    >>
    >> --Randy Starkey
    >>

    >
    >




  4. #4
    Nick Hodge
    Guest

    Re: autofit row code

    certainly

    --
    HTH
    Nick Hodge
    Microsoft MVP - Excel
    Southampton, England
    [email protected]HIS


    "Randy Starkey" <[email protected]> wrote in
    message news:[email protected]...
    > Nick,
    >
    > Can I do...
    >
    > .Rows("1:3").AutoFit
    >
    > Thanks!
    >
    > --Randy
    >
    >
    > "Nick Hodge" <[email protected]> wrote in message
    > news:%[email protected]...
    >> Randy
    >>
    >> I suppose it doesn't matter if you autofit *all* rows (inc 1-3?)
    >>
    >> You could then simply put above the End With statement
    >>
    >> .Rows.AutoFit
    >>
    >> If you then need to set back the top three you could do that with
    >>
    >> .Rows("1:3").RowHeight = 12
    >>
    >> --
    >> HTH
    >> Nick Hodge
    >> Microsoft MVP - Excel
    >> Southampton, England
    >> [email protected]HIS
    >>
    >>
    >> "Randy Starkey" <[email protected]> wrote in
    >> message news:[email protected]...
    >>>I would like to look at all rows in an active sheet (from row 3 down) and
    >>>then autofit the rows. I'd like to add this to my sort macro.
    >>>
    >>> Here's what I've got...
    >>>
    >>> Sub Hospital_Sheet_Sort()
    >>> Dim myRng As Range
    >>>
    >>> With ActiveSheet
    >>> Set myRng = .Range("A3:V" & .Cells(.Rows.Count, "A").End(xlUp).Row)
    >>> myRng.Sort Key1:=Range("A3"), Order1:=xlAscending, Key2:=Range("N3")
    >>> _
    >>> , Order2:=xlDescending, Header:=xlNo, OrderCustom:=1,
    >>> MatchCase:=False _
    >>> , Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
    >>> DataOption2:= _
    >>> xlSortNormal
    >>> End With
    >>> myRng.AutoFit.Row
    >>> Range("A3:A3").Select
    >>> End Sub
    >>>
    >>> I get an error on the myRng autofitting.
    >>> I'm doing something wrong obviously...
    >>> Any help would be appreciated.
    >>>
    >>> Thanks!
    >>>
    >>> --Randy Starkey
    >>>

    >>
    >>

    >
    >




  5. #5
    Randy Starkey
    Guest

    Re: autofit row code

    Nick,

    I wonder if I had this backwards...

    myRng.AutoFit.Row
    should it simply be...
    myRng.Row.AutoFit ?

    Thanks!

    --Randy


    "Nick Hodge" <[email protected]> wrote in message
    news:[email protected]...
    > certainly
    >
    > --
    > HTH
    > Nick Hodge
    > Microsoft MVP - Excel
    > Southampton, England
    > [email protected]HIS
    >
    >
    > "Randy Starkey" <[email protected]> wrote in
    > message news:[email protected]...
    >> Nick,
    >>
    >> Can I do...
    >>
    >> .Rows("1:3").AutoFit
    >>
    >> Thanks!
    >>
    >> --Randy
    >>
    >>
    >> "Nick Hodge" <[email protected]> wrote in message
    >> news:%[email protected]...
    >>> Randy
    >>>
    >>> I suppose it doesn't matter if you autofit *all* rows (inc 1-3?)
    >>>
    >>> You could then simply put above the End With statement
    >>>
    >>> .Rows.AutoFit
    >>>
    >>> If you then need to set back the top three you could do that with
    >>>
    >>> .Rows("1:3").RowHeight = 12
    >>>
    >>> --
    >>> HTH
    >>> Nick Hodge
    >>> Microsoft MVP - Excel
    >>> Southampton, England
    >>> [email protected]HIS
    >>>
    >>>
    >>> "Randy Starkey" <[email protected]> wrote in
    >>> message news:[email protected]...
    >>>>I would like to look at all rows in an active sheet (from row 3 down)
    >>>>and then autofit the rows. I'd like to add this to my sort macro.
    >>>>
    >>>> Here's what I've got...
    >>>>
    >>>> Sub Hospital_Sheet_Sort()
    >>>> Dim myRng As Range
    >>>>
    >>>> With ActiveSheet
    >>>> Set myRng = .Range("A3:V" & .Cells(.Rows.Count, "A").End(xlUp).Row)
    >>>> myRng.Sort Key1:=Range("A3"), Order1:=xlAscending, Key2:=Range("N3")
    >>>> _
    >>>> , Order2:=xlDescending, Header:=xlNo, OrderCustom:=1,
    >>>> MatchCase:=False _
    >>>> , Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
    >>>> DataOption2:= _
    >>>> xlSortNormal
    >>>> End With
    >>>> myRng.AutoFit.Row
    >>>> Range("A3:A3").Select
    >>>> End Sub
    >>>>
    >>>> I get an error on the myRng autofitting.
    >>>> I'm doing something wrong obviously...
    >>>> Any help would be appreciated.
    >>>>
    >>>> Thanks!
    >>>>
    >>>> --Randy Starkey
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >




  6. #6
    Nick Hodge
    Guest

    Re: autofit row code

    Randy

    Yes...the second is the correct syntax, but you need rowS

    ..Rows.Autofit

    Note: In the 'With.... End With' statement, you are already utilising the
    ActiveSheet, so you don't need the range variable at this time because the
    statement refers to all the rows on the activesheet this way.

    --
    HTH
    Nick Hodge
    Microsoft MVP - Excel
    Southampton, England
    [email protected]HIS


    "Randy Starkey" <[email protected]> wrote in
    message news:[email protected]...
    > Nick,
    >
    > I wonder if I had this backwards...
    >
    > myRng.AutoFit.Row
    > should it simply be...
    > myRng.Row.AutoFit ?
    >
    > Thanks!
    >
    > --Randy
    >
    >
    > "Nick Hodge" <[email protected]> wrote in message
    > news:[email protected]...
    >> certainly
    >>
    >> --
    >> HTH
    >> Nick Hodge
    >> Microsoft MVP - Excel
    >> Southampton, England
    >> [email protected]HIS
    >>
    >>
    >> "Randy Starkey" <[email protected]> wrote in
    >> message news:[email protected]...
    >>> Nick,
    >>>
    >>> Can I do...
    >>>
    >>> .Rows("1:3").AutoFit
    >>>
    >>> Thanks!
    >>>
    >>> --Randy
    >>>
    >>>
    >>> "Nick Hodge" <[email protected]> wrote in message
    >>> news:%[email protected]...
    >>>> Randy
    >>>>
    >>>> I suppose it doesn't matter if you autofit *all* rows (inc 1-3?)
    >>>>
    >>>> You could then simply put above the End With statement
    >>>>
    >>>> .Rows.AutoFit
    >>>>
    >>>> If you then need to set back the top three you could do that with
    >>>>
    >>>> .Rows("1:3").RowHeight = 12
    >>>>
    >>>> --
    >>>> HTH
    >>>> Nick Hodge
    >>>> Microsoft MVP - Excel
    >>>> Southampton, England
    >>>> [email protected]HIS
    >>>>
    >>>>
    >>>> "Randy Starkey" <[email protected]> wrote in
    >>>> message news:[email protected]...
    >>>>>I would like to look at all rows in an active sheet (from row 3 down)
    >>>>>and then autofit the rows. I'd like to add this to my sort macro.
    >>>>>
    >>>>> Here's what I've got...
    >>>>>
    >>>>> Sub Hospital_Sheet_Sort()
    >>>>> Dim myRng As Range
    >>>>>
    >>>>> With ActiveSheet
    >>>>> Set myRng = .Range("A3:V" & .Cells(.Rows.Count, "A").End(xlUp).Row)
    >>>>> myRng.Sort Key1:=Range("A3"), Order1:=xlAscending,
    >>>>> Key2:=Range("N3") _
    >>>>> , Order2:=xlDescending, Header:=xlNo, OrderCustom:=1,
    >>>>> MatchCase:=False _
    >>>>> , Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
    >>>>> DataOption2:= _
    >>>>> xlSortNormal
    >>>>> End With
    >>>>> myRng.AutoFit.Row
    >>>>> Range("A3:A3").Select
    >>>>> End Sub
    >>>>>
    >>>>> I get an error on the myRng autofitting.
    >>>>> I'm doing something wrong obviously...
    >>>>> Any help would be appreciated.
    >>>>>
    >>>>> Thanks!
    >>>>>
    >>>>> --Randy Starkey
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >




  7. #7
    Randy Starkey
    Guest

    Re: autofit row code

    Nick,

    Ah! Yes. The thing I liked about using the myRng is it leaves off rows 1-3,
    correct?

    --Randy


    "Nick Hodge" <[email protected]> wrote in message
    news:[email protected]...
    > Randy
    >
    > Yes...the second is the correct syntax, but you need rowS
    >
    > .Rows.Autofit
    >
    > Note: In the 'With.... End With' statement, you are already utilising the
    > ActiveSheet, so you don't need the range variable at this time because the
    > statement refers to all the rows on the activesheet this way.
    >
    > --
    > HTH
    > Nick Hodge
    > Microsoft MVP - Excel
    > Southampton, England
    > [email protected]HIS
    >
    >
    > "Randy Starkey" <[email protected]> wrote in
    > message news:[email protected]...
    >> Nick,
    >>
    >> I wonder if I had this backwards...
    >>
    >> myRng.AutoFit.Row
    >> should it simply be...
    >> myRng.Row.AutoFit ?
    >>
    >> Thanks!
    >>
    >> --Randy
    >>
    >>
    >> "Nick Hodge" <[email protected]> wrote in message
    >> news:[email protected]...
    >>> certainly
    >>>
    >>> --
    >>> HTH
    >>> Nick Hodge
    >>> Microsoft MVP - Excel
    >>> Southampton, England
    >>> [email protected]HIS
    >>>
    >>>
    >>> "Randy Starkey" <[email protected]> wrote in
    >>> message news:[email protected]...
    >>>> Nick,
    >>>>
    >>>> Can I do...
    >>>>
    >>>> .Rows("1:3").AutoFit
    >>>>
    >>>> Thanks!
    >>>>
    >>>> --Randy
    >>>>
    >>>>
    >>>> "Nick Hodge" <[email protected]> wrote in message
    >>>> news:%[email protected]...
    >>>>> Randy
    >>>>>
    >>>>> I suppose it doesn't matter if you autofit *all* rows (inc 1-3?)
    >>>>>
    >>>>> You could then simply put above the End With statement
    >>>>>
    >>>>> .Rows.AutoFit
    >>>>>
    >>>>> If you then need to set back the top three you could do that with
    >>>>>
    >>>>> .Rows("1:3").RowHeight = 12
    >>>>>
    >>>>> --
    >>>>> HTH
    >>>>> Nick Hodge
    >>>>> Microsoft MVP - Excel
    >>>>> Southampton, England
    >>>>> [email protected]HIS
    >>>>>
    >>>>>
    >>>>> "Randy Starkey" <[email protected]> wrote in
    >>>>> message news:[email protected]...
    >>>>>>I would like to look at all rows in an active sheet (from row 3 down)
    >>>>>>and then autofit the rows. I'd like to add this to my sort macro.
    >>>>>>
    >>>>>> Here's what I've got...
    >>>>>>
    >>>>>> Sub Hospital_Sheet_Sort()
    >>>>>> Dim myRng As Range
    >>>>>>
    >>>>>> With ActiveSheet
    >>>>>> Set myRng = .Range("A3:V" & .Cells(.Rows.Count,
    >>>>>> "A").End(xlUp).Row)
    >>>>>> myRng.Sort Key1:=Range("A3"), Order1:=xlAscending,
    >>>>>> Key2:=Range("N3") _
    >>>>>> , Order2:=xlDescending, Header:=xlNo, OrderCustom:=1,
    >>>>>> MatchCase:=False _
    >>>>>> , Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
    >>>>>> DataOption2:= _
    >>>>>> xlSortNormal
    >>>>>> End With
    >>>>>> myRng.AutoFit.Row
    >>>>>> Range("A3:A3").Select
    >>>>>> End Sub
    >>>>>>
    >>>>>> I get an error on the myRng autofitting.
    >>>>>> I'm doing something wrong obviously...
    >>>>>> Any help would be appreciated.
    >>>>>>
    >>>>>> Thanks!
    >>>>>>
    >>>>>> --Randy Starkey
    >>>>>>
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >




  8. #8
    Nick Hodge
    Guest

    Re: autofit row code

    Correct

    --
    HTH
    Nick Hodge
    Microsoft MVP - Excel
    Southampton, England
    [email protected]HIS


    "Randy Starkey" <[email protected]> wrote in
    message news:[email protected]...
    > Nick,
    >
    > Ah! Yes. The thing I liked about using the myRng is it leaves off rows
    > 1-3, correct?
    >
    > --Randy
    >
    >
    > "Nick Hodge" <[email protected]> wrote in message
    > news:[email protected]...
    >> Randy
    >>
    >> Yes...the second is the correct syntax, but you need rowS
    >>
    >> .Rows.Autofit
    >>
    >> Note: In the 'With.... End With' statement, you are already utilising the
    >> ActiveSheet, so you don't need the range variable at this time because
    >> the statement refers to all the rows on the activesheet this way.
    >>
    >> --
    >> HTH
    >> Nick Hodge
    >> Microsoft MVP - Excel
    >> Southampton, England
    >> [email protected]HIS
    >>
    >>
    >> "Randy Starkey" <[email protected]> wrote in
    >> message news:[email protected]...
    >>> Nick,
    >>>
    >>> I wonder if I had this backwards...
    >>>
    >>> myRng.AutoFit.Row
    >>> should it simply be...
    >>> myRng.Row.AutoFit ?
    >>>
    >>> Thanks!
    >>>
    >>> --Randy
    >>>
    >>>
    >>> "Nick Hodge" <[email protected]> wrote in message
    >>> news:[email protected]...
    >>>> certainly
    >>>>
    >>>> --
    >>>> HTH
    >>>> Nick Hodge
    >>>> Microsoft MVP - Excel
    >>>> Southampton, England
    >>>> [email protected]HIS
    >>>>
    >>>>
    >>>> "Randy Starkey" <[email protected]> wrote in
    >>>> message news:[email protected]...
    >>>>> Nick,
    >>>>>
    >>>>> Can I do...
    >>>>>
    >>>>> .Rows("1:3").AutoFit
    >>>>>
    >>>>> Thanks!
    >>>>>
    >>>>> --Randy
    >>>>>
    >>>>>
    >>>>> "Nick Hodge" <[email protected]> wrote in
    >>>>> message news:%[email protected]...
    >>>>>> Randy
    >>>>>>
    >>>>>> I suppose it doesn't matter if you autofit *all* rows (inc 1-3?)
    >>>>>>
    >>>>>> You could then simply put above the End With statement
    >>>>>>
    >>>>>> .Rows.AutoFit
    >>>>>>
    >>>>>> If you then need to set back the top three you could do that with
    >>>>>>
    >>>>>> .Rows("1:3").RowHeight = 12
    >>>>>>
    >>>>>> --
    >>>>>> HTH
    >>>>>> Nick Hodge
    >>>>>> Microsoft MVP - Excel
    >>>>>> Southampton, England
    >>>>>> [email protected]HIS
    >>>>>>
    >>>>>>
    >>>>>> "Randy Starkey" <[email protected]> wrote
    >>>>>> in message news:[email protected]...
    >>>>>>>I would like to look at all rows in an active sheet (from row 3 down)
    >>>>>>>and then autofit the rows. I'd like to add this to my sort macro.
    >>>>>>>
    >>>>>>> Here's what I've got...
    >>>>>>>
    >>>>>>> Sub Hospital_Sheet_Sort()
    >>>>>>> Dim myRng As Range
    >>>>>>>
    >>>>>>> With ActiveSheet
    >>>>>>> Set myRng = .Range("A3:V" & .Cells(.Rows.Count,
    >>>>>>> "A").End(xlUp).Row)
    >>>>>>> myRng.Sort Key1:=Range("A3"), Order1:=xlAscending,
    >>>>>>> Key2:=Range("N3") _
    >>>>>>> , Order2:=xlDescending, Header:=xlNo, OrderCustom:=1,
    >>>>>>> MatchCase:=False _
    >>>>>>> , Orientation:=xlTopToBottom, DataOption1:=xlSortNormal,
    >>>>>>> DataOption2:= _
    >>>>>>> xlSortNormal
    >>>>>>> End With
    >>>>>>> myRng.AutoFit.Row
    >>>>>>> Range("A3:A3").Select
    >>>>>>> End Sub
    >>>>>>>
    >>>>>>> I get an error on the myRng autofitting.
    >>>>>>> I'm doing something wrong obviously...
    >>>>>>> Any help would be appreciated.
    >>>>>>>
    >>>>>>> Thanks!
    >>>>>>>
    >>>>>>> --Randy Starkey
    >>>>>>>
    >>>>>>
    >>>>>>
    >>>>>
    >>>>>
    >>>>
    >>>>
    >>>
    >>>

    >>
    >>

    >
    >




+ 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