Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy error with Autofilter

I'm getting a Run-time error '1004' Copy method of Range Class faile
when I run the code below. (i.e. at the rng.copy line)

My data starts in Column B and I want the column headings copied to th
destination sheet too. The correct data is copied to the destinatio
sheet before the error occurs.

I've used (and slightly modified) Tom Ogilvy's code - which is ofte
quoted on this forum - so I pretty much know its something I've done!

I'm rather a newbie to VBA I'm afraid...

Using Excel 2003

Sub aaddAutofileterdData()

'by Tom Ogilvy (mostly)
Dim rng As Range
Dim rng2 As Range

If Not Worksheets("Data").AutoFilterMode Then
Worksheets("Data").Range("B1:AB1").AutoFilter
End If

Sheets("Data").Activate

With ActiveSheet.AutoFilter.Range

Selection.AutoFilter Field:=11, Criteria1:="Marketing"
Selection.AutoFilter Field:=12, Criteria1:="Cluster"

On Error Resume Next
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If rng2 Is Nothing Then
MsgBox "No data to copy"
Else
Worksheets("Mkting Clusters").Cells.Clear
Set rng = ActiveSheet.AutoFilter.Range
rng.Copy _
Destination:=Worksheets("Mkting Clusters").Range("A1")
End If
ActiveSheet.ShowAllData
End Sub


Any help would be greatly appreciated
Thanks
Jonatha

--
Message posted from http://www.ExcelForum.com

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
Excel Autofilter Error linglc Excel Discussion (Misc queries) 1 January 23rd 08 01:14 AM
Excel Autofilter error linglc Excel Discussion (Misc queries) 0 January 23rd 08 12:20 AM
AUTOFILTER copy and paste RJ Kelly Excel Programming 1 June 8th 04 11:40 AM
autofilter macro causes #VALUE! error Jill[_7_] Excel Programming 3 May 5th 04 12:02 AM
VBA Autofilter error in '97, not 2000 Foggy Excel Programming 3 April 3rd 04 03:57 AM


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