Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

range selection.copy works in Excel 2000 but not in 2003

Status
Not open for further replies.

carambaxa

MIS
Mar 18, 2005
1
US
Help - this code works fine in Excel 2000 but gets a Run-Time error '1004' (Copy method of Range class failed)in Excel 2003. It may have something to do with the fact that the data on the sendingsheet has been filtered? The strange thing is that the data actually gets moved to the other sheet before the error shows. For some reason or other the 'D' column on the receiving sheet is highlighted as though it had been selected. If I click on one of the three columns I need and 'deselect' that column I can continue the run and the job completes. Have been unable to get any answers about the process differences between Excel 2000 and 2003 that would cause this. Willing to try any suggestions. Thanks. carambax


Worksheets(3).Range("A1").AutoFilter _
Field:=1, Criteria1:="audit"
'hide column 1 so it won't be selected
Columns("A:A").Select
Selection.EntireColumn.Hidden = True
'select all cells that have are visible
Range("B1").CurrentRegion.SpecialCells(xlVisible).Select
'Copy the visible cells to worksheet RandSel.
Selection.Copy Worksheets("RandSel").Range("A2")

****the last line is the line that gets highlighted by debug. The next line selects a different worksheet for some housekeeping. Thanks for your time and consideration.
 
Hi,

This ought to be enough
Code:
With Worksheets(3).Range("A1")
    .AutoFilter _
        Field:=1, Criteria1:="audit"

    With .CurrentRegion
        Range(Cells(1, "B"), Cells(.Rows.Count, .Columns.Count)).SpecialCells(xlVisible).Copy _
            Worksheets("RandSel").Range("A2")
    End With
End With


Skip,

[glasses] [red]Be advised:[/red] When you ignite a firecracker in a bowl of vanilla, chocolate & strawberry ice cream, you get...
Neopolitan Blownapart! [tongue]


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top