Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default Named Range question

The following code copies two columns on 10 different worksheets within a
workbook. The code works perfectly 12 times but on the 13th run it gets the
error run time error 1004 autofill method of range class failed. This error
happens on the line
SourceRange.AutoFill Destination:=DestinationRange, Type:=xlFillDefault
on the 7th time through the loop. Is there a limit to size of a named
range? Any other ideas why it would fail?

Sub COLUMN_COPY()
'
' COLUMN_COPY Macro
' Macro recorded 10/7/2005 by Dave Sheldon
'

'
Dim SourceRange As Range
Dim DestinationRange As Range
Dim NumColumns As Integer
Dim i As Integer

For i = 1 To 10
NumColumns = Worksheets(i).Range("col").Columns.Count
Set SourceRange = Worksheets(i).Range("col")
Set DestinationRange = Worksheets(i).Range("col").Resize(,
NumColumns + 2)
SourceRange.AutoFill Destination:=DestinationRange,
Type:=xlFillDefault
Worksheets(i).Range("col").Resize(, NumColumns + 2).Name =
Worksheets(i).Name & "!" & "col"
If Worksheets(i).Name = "ESTIMATE" Or Worksheets(i).Name = "SUMMARY"
Then
Worksheets(i).Range("col").Columns(NumColumns + 1).Hidden = True
End If
Next i

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Named Range question

Not sure what the Range named "col" is to start with but one possible cause
is that you are exceeding the 256 column limit of Excel when redefining the
target range??

--
Cheers
Nigel



"Dave" wrote in message
...
The following code copies two columns on 10 different worksheets within a
workbook. The code works perfectly 12 times but on the 13th run it gets

the
error run time error 1004 autofill method of range class failed. This

error
happens on the line
SourceRange.AutoFill Destination:=DestinationRange, Type:=xlFillDefault
on the 7th time through the loop. Is there a limit to size of a named
range? Any other ideas why it would fail?

Sub COLUMN_COPY()
'
' COLUMN_COPY Macro
' Macro recorded 10/7/2005 by Dave Sheldon
'

'
Dim SourceRange As Range
Dim DestinationRange As Range
Dim NumColumns As Integer
Dim i As Integer

For i = 1 To 10
NumColumns = Worksheets(i).Range("col").Columns.Count
Set SourceRange = Worksheets(i).Range("col")
Set DestinationRange = Worksheets(i).Range("col").Resize(,
NumColumns + 2)
SourceRange.AutoFill Destination:=DestinationRange,
Type:=xlFillDefault
Worksheets(i).Range("col").Resize(, NumColumns + 2).Name =
Worksheets(i).Name & "!" & "col"
If Worksheets(i).Name = "ESTIMATE" Or Worksheets(i).Name =

"SUMMARY"
Then
Worksheets(i).Range("col").Columns(NumColumns + 1).Hidden =

True
End If
Next i

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,388
Default Named Range question

Nigel

Thanks for the response but at the point when the procedure fails the amount
of columns in the named range is 26

"Nigel" wrote:

Not sure what the Range named "col" is to start with but one possible cause
is that you are exceeding the 256 column limit of Excel when redefining the
target range??

--
Cheers
Nigel



"Dave" wrote in message
...
The following code copies two columns on 10 different worksheets within a
workbook. The code works perfectly 12 times but on the 13th run it gets

the
error run time error 1004 autofill method of range class failed. This

error
happens on the line
SourceRange.AutoFill Destination:=DestinationRange, Type:=xlFillDefault
on the 7th time through the loop. Is there a limit to size of a named
range? Any other ideas why it would fail?

Sub COLUMN_COPY()
'
' COLUMN_COPY Macro
' Macro recorded 10/7/2005 by Dave Sheldon
'

'
Dim SourceRange As Range
Dim DestinationRange As Range
Dim NumColumns As Integer
Dim i As Integer

For i = 1 To 10
NumColumns = Worksheets(i).Range("col").Columns.Count
Set SourceRange = Worksheets(i).Range("col")
Set DestinationRange = Worksheets(i).Range("col").Resize(,
NumColumns + 2)
SourceRange.AutoFill Destination:=DestinationRange,
Type:=xlFillDefault
Worksheets(i).Range("col").Resize(, NumColumns + 2).Name =
Worksheets(i).Name & "!" & "col"
If Worksheets(i).Name = "ESTIMATE" Or Worksheets(i).Name =

"SUMMARY"
Then
Worksheets(i).Range("col").Columns(NumColumns + 1).Hidden =

True
End If
Next i

End 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
Named Range Question PA New Users to Excel 2 December 4th 08 08:07 PM
Named Range Question. LuftRider Excel Discussion (Misc queries) 3 September 24th 07 08:17 PM
Named Range Question Barb Reinhardt Excel Worksheet Functions 4 September 27th 06 04:10 PM
Named range question Shane Henderson Excel Discussion (Misc queries) 2 April 7th 06 03:38 AM
Named Range Question Ray Batig Excel Programming 2 August 6th 04 12:55 AM


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