Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default 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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default 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" wrote in message
...
certainly

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"Randy Starkey" wrote in
message ...
Nick,

Can I do...

.Rows("1:3").AutoFit

Thanks!

--Randy


"Nick Hodge" wrote in message
...
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
HIS


"Randy Starkey" wrote in
message ...
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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,173
Default 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
HIS


"Randy Starkey" wrote in
message ...
Nick,

I wonder if I had this backwards...

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

Thanks!

--Randy


"Nick Hodge" wrote in message
...
certainly

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS


"Randy Starkey" wrote in
message ...
Nick,

Can I do...

.Rows("1:3").AutoFit

Thanks!

--Randy


"Nick Hodge" wrote in message
...
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
HIS


"Randy Starkey" wrote in
message ...
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
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 Merged cell Code is changing the format of my merged cells JB Excel Discussion (Misc queries) 0 August 20th 07 02:12 PM
Need code to Autofit Row Height on recalculation Bob Tarburton Excel Discussion (Misc queries) 0 March 4th 05 08:31 PM
Code for autofit/merged cells doesn't work Janet[_4_] Excel Programming 1 January 29th 04 02:39 AM
Merged Cells Autofit - code amendment roy Excel Programming 7 November 4th 03 12:19 PM


All times are GMT +1. The time now is 06:29 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"