Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default AutoFit method of Range class failed

The following are the simple few lines of code to adjust
the height of rows when user clicks the "Adjust Rows"
button. I keep on getting a run-time error "1004" saying
AutFit method of Range class failed.

Can someone please tell me where it fails ?

PS: The column contains data need adjust is Column D with
with more than 999 rows of data.

Private sub Adjust_Rows_Click()
Dim Rows as Integer

Rows = ActiveSheet.Range("D999").End(xlUp).Row
ActiveSheet.Range("D4:D"+Cstr(Rows)).Rows.AutoFit
End Sub



Thanks in advance for any help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default AutoFit method of Range class failed

First, I'd stay away from using VBA terms as my variable (Rows)

And when you're working with strings, it's better to use "&" to concatenate
(instead of "+").

This worked ok for me:

Option Explicit

Private Sub Adjust_Rows_Click()
Dim LastRow As Long
With ActiveSheet
LastRow = .Range("D65536").End(xlUp).Row
.Range("D4:D" & LastRow).EntireRow.AutoFit
End With
End Sub

(I didn't need the cstr() function. VBA is forgiving of some things.)



Wellie wrote:

The following are the simple few lines of code to adjust
the height of rows when user clicks the "Adjust Rows"
button. I keep on getting a run-time error "1004" saying
AutFit method of Range class failed.

Can someone please tell me where it fails ?

PS: The column contains data need adjust is Column D with
with more than 999 rows of data.

Private sub Adjust_Rows_Click()
Dim Rows as Integer

Rows = ActiveSheet.Range("D999").End(xlUp).Row
ActiveSheet.Range("D4:D"+Cstr(Rows)).Rows.AutoFit
End Sub

Thanks in advance for any help.


--

Dave Peterson

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
Autofill method of range class failed Don Guillett Excel Discussion (Misc queries) 0 February 27th 08 03:56 PM
Autofill method of range class failed Appache Excel Discussion (Misc queries) 5 February 27th 08 03:37 PM
Run-time error '1004' PasteSpecial Method of Range Class Failed Kevin G[_2_] Excel Programming 1 February 3rd 04 05:01 AM
VB Error: Paste Special method of range class failed Chris Excel Programming 2 January 30th 04 12:51 PM
error 1004 Select method of Range class failed J.E. McGimpsey Excel Programming 1 September 12th 03 07:42 PM


All times are GMT +1. The time now is 06:25 PM.

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"