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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel Sheets(Array(---)).copy problem 1

Status
Not open for further replies.

JamesDSM50328

Technical User
Mar 25, 2005
33
US
I need some assistance with a Sheet(Array(---)).copy. I have a worksheet that contains the names of the other worksheets if indicated will be copied to a new workbook.

the code loops through and creates an array for the sheets that it needs to copy, but it errors on the line
Code:
origwb.Sheets(Array(sheetArray)).Copy

Error: -2147417848(80010108) Method 'COPY' of 'Sheets' failed.

Code:
...
set origwb=thisworkbook
For a = tr To lr
    
    If IsEmpty(origwb.Sheets("CoverPage").Cells(a, c2)) = False Then
    
    For b = ts To ls
        sheetNames = sheetNames & origwb.Sheets("CoverPage").Cells(a, c1).Value & " " & origwb.Sheets("CoverPage").Cells(b, s1).Value & ","
    
    Next b
        
        sheetNames = Mid(sheetNames, 1, Len(sheetNames) - 1)
        sheetArray = Split(CStr(sheetNames), ",")
        
        origwb.Sheets(Array(sheetArray)).Copy
        
        set destwb = ActiveWorkbook
        
        sheetNames=""
    End If
        
Next a
 
The function, Split, returns an array, so your variable, "sheetArray" is already an array. I think that makes your statement, "Array(sheetArray)", redundant and, probably, illegal. Furthermore, you probably mean for each element of that array to be a separate sheet name. Therefore, you need to loop through all the elements of the array (as in: for i=0 to ubound(sheetArray), origwb.Sheets(sheetArray(i)).copy, etc).

_________________
Bob Rashkin
 
THANKS, the issue was that the sheetArray was already an array, and the Array(sheetArray)was the illegal. Thanks for the help!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top