Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 57
Default Loop through range, Autofit height

This is a sub I made to loop through a range and autofit row height of each
row:

Sub AutoHeight()
Dim c As Range
For Each c In Sheet1.Range("AutoFit")
Rows.AutoFit
Next c
End Sub

The macro just keeps running and running. What;'s wrong with my sub?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Loop through range, Autofit height

What are your parameters for the range named "AutoFit", which, by the way,
is a bad practice to use reserved words for names and variables.


"John" wrote in message
...
This is a sub I made to loop through a range and autofit row height of
each row:

Sub AutoHeight()
Dim c As Range
For Each c In Sheet1.Range("AutoFit")
Rows.AutoFit
Next c
End Sub

The macro just keeps running and running. What;'s wrong with my sub?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Loop through range, Autofit height

Firstly, make sure you always have Option Explicit at the top of every
module and form.
You will see why when you try to run the code you posted with that done.

Then try code like this:

Sub AutoHeight()

Dim r As Long

With Sheets("Sheet1").Range("AutoFit")
For r = 1 To .Rows.Count
.Rows(r).AutoFit
Next r
End With

End Sub


RBS


"John" wrote in message
...
This is a sub I made to loop through a range and autofit row height of
each row:

Sub AutoHeight()
Dim c As Range
For Each c In Sheet1.Range("AutoFit")
Rows.AutoFit
Next c
End Sub

The macro just keeps running and running. What;'s wrong with my sub?


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Loop through range, Autofit height

This might work better if the named range is defined.

Sub AutoHeight()
Sheets("Sheet1".Range("AutoFit").Rows.AutoFit
End Sub





"John" wrote in message
...
This is a sub I made to loop through a range and autofit row height of
each row:

Sub AutoHeight()
Dim c As Range
For Each c In Sheet1.Range("AutoFit")
Rows.AutoFit
Next c
End Sub

The macro just keeps running and running. What;'s wrong with my sub?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Loop through range, Autofit height

Sheets("Sheet1".Range("AutoFit").Rows.AutoFit

Ah, yes, of course no need for the loop as I posted.

RBS


"JLGWhiz" wrote in message
...
This might work better if the named range is defined.

Sub AutoHeight()
Sheets("Sheet1".Range("AutoFit").Rows.AutoFit
End Sub





"John" wrote in message
...
This is a sub I made to loop through a range and autofit row height of
each row:

Sub AutoHeight()
Dim c As Range
For Each c In Sheet1.Range("AutoFit")
Rows.AutoFit
Next c
End Sub

The macro just keeps running and running. What;'s wrong with my sub?






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Loop through range, Autofit height


works even better with the parentheses in place:

Sub AutoHeight()
Sheets("Sheet1").Range("AutoFit").Rows.AutoFit
End Sub



"RB Smissaert" wrote in message
...
Sheets("Sheet1".Range("AutoFit").Rows.AutoFit


Ah, yes, of course no need for the loop as I posted.

RBS


"JLGWhiz" wrote in message
...
This might work better if the named range is defined.

Sub AutoHeight()
Sheets("Sheet1".Range("AutoFit").Rows.AutoFit
End Sub





"John" wrote in message
...
This is a sub I made to loop through a range and autofit row height of
each row:

Sub AutoHeight()
Dim c As Range
For Each c In Sheet1.Range("AutoFit")
Rows.AutoFit
Next c
End Sub

The macro just keeps running and running. What;'s wrong with my sub?






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Loop through range, Autofit height

Ah, yes, infinite better!

RBS


"JLGWhiz" wrote in message
...

works even better with the parentheses in place:

Sub AutoHeight()
Sheets("Sheet1").Range("AutoFit").Rows.AutoFit
End Sub



"RB Smissaert" wrote in message
...
Sheets("Sheet1".Range("AutoFit").Rows.AutoFit


Ah, yes, of course no need for the loop as I posted.

RBS


"JLGWhiz" wrote in message
...
This might work better if the named range is defined.

Sub AutoHeight()
Sheets("Sheet1".Range("AutoFit").Rows.AutoFit
End Sub





"John" wrote in message
...
This is a sub I made to loop through a range and autofit row height of
each row:

Sub AutoHeight()
Dim c As Range
For Each c In Sheet1.Range("AutoFit")
Rows.AutoFit
Next c
End Sub

The macro just keeps running and running. What;'s wrong with my sub?







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
Set a minimum row height a the same time with autofit row height Julie B New Users to Excel 2 May 5th 23 07:44 PM
Autofit Row Height jkiser Excel Discussion (Misc queries) 3 June 2nd 10 12:21 AM
Autofit row height Odie Excel Discussion (Misc queries) 7 April 12th 08 07:25 PM
Need a row to autofit height after it's value changes Rob E[_2_] Excel Discussion (Misc queries) 6 June 20th 07 08:00 PM
Autofit row height Wellie Excel Programming 2 February 28th 05 02:03 AM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"