0
votes

I'm getting this error :

Run-time error '1004': Copy Method of Worksheet Class failed

We're trying to create new sheets from a base sheet. This code needs to copy the base sheet's elements and put them in a new sheet and works perfectly on my co-worker's computer but not on mine I don't know why. I've checked several related questions but there is no use for me.

    Sub Otomatik_CategoryMenuleriniOlustur()
    Dim ToplamCategoryMenuSayisi As String
    Dim Pos As Long

    Sheets("Otomatik_ID_Category").Select

    Range("C8:C1000000").Select
    Selection.Find(What:="", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate

    AktifSatir = ActiveCell.Row

    ToplamCategoryMenuSayisi = AktifSatir - 9

    'MsgBox ToplamCategoryMenuSayisi

    Range("A1").Select

    Call forEachWs_Urunler_Category_Orj_Sayfa_Pozisyonunu_Bul

    'MsgBox "Urunler Category Orj Sayfasýnýn Sayýsý Konumu : " & Urunler_Category_Orj_Sayfa_Pozisyonu

    j = 0

    For i = 9 To ToplamCategoryMenuSayisi + 8


            Pos = InStr(Cells(i, 3), "Pizza")
            If Pos > 0 Then

                            'MsgBox Cells(i, 3) & " Hücresinin " & Pos & " pozisyonunda Pizza Bulundu. Sayfasý Eklenmeyecek"
                            j = j + 1


                       Else

                            Sheets("Urunler Category Orj").Copy After:=Sheets(Urunler_Category_Orj_Sayfa_Pozisyonu + j)
                            j = j + 1

                            EklenenSayfa = ActiveSheet.Name
                            'MsgBox EklenenSayfa
                            SayfaAdi = Sheets("Otomatik_ID_Category").Cells(i, 3).Text
                            'MsgBox SayfaAdi
                            'Sheets("Urunler Category Orj (2)").Select
                            Sheets(EklenenSayfa).Name = SayfaAdi

                            Cells(7, 4).Value = SayfaAdi & ".png"

                            Cells(7, 2).Value = Sheets("Otomatik_ID_Category").Cells(i, 1).Text

                            Cells(7, 1).Value = (i - 7) * 1000


            End If
                'HucreIcerigi = Search




    Next i

    Sheets("Otomatik_ID_Category").Select

End Sub

-

The highlighted line is this :

Sheets("Urunler Category Orj").Copy After:=Sheets(Urunler_Category_Orj_Sayfa_Pozisyonu + j)

The excel file if needed : Tablo Yapisi Macro BA.xlsm

1
can you upload full code?. - Dang D. Khanh
@TheGridLock I've uploaded the Excel file. - Oğuzhan Varsak

1 Answers

0
votes

It is failing because you have not assigned a value to:

Urunler_Category_Orj_Sayfa_Pozisyonu