Copy a worksheet to the end of the workbook.

Jerald_Rufus

New Member
Joined
Jun 19, 2017
Messages
2
Hi,

I am new to VBA, to be frank I am new to Excel.

I needed to copy a sheet to the end of the workbook and rename with a value of cell in another sheet of the same workbook and copy some values for another sheet.

I manage type some code based on the results i get in web but i am getting

"Run-time error '424':
Object Required."

The sheet which I am trying to copy has Buttons and the code for it.

Below is the code.

Code:
Private Sub Seperate_Click()


Dim no_assy As Variant
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim assy As String
Dim ws As Worksheet
Dim lRow As Long
Dim l As Integer
Dim m As Integer


    lRow = Worksheets("PART LIST").Cells.Find(what:="*", _
                    After:=Range("A1"), _
                    LookAt:=xlPart, _
                    LookIn:=xlFormulas, _
                    searchorder:=xlByRows, _
                    searchdirection:=xlPrevious, _
                    MatchCase:=False).Row
    
no_assy = InputBox("Enter number of Item")
no_assy = no_assy + 2
    For i = 3 To no_assy
        l = 3
        assy = Worksheets("PART LIST").Cells(1, i)
        m = ThisWorkbook.Sheets.Count
        Set ws = ThisWorkbook.Sheets("CompTemplate").Copy(After:=Worksheets(m))
        ws.Name = assy
           For j = 2 To lRow
                If IsEmpty(Worksheets("PART LIST").Cells(j, i).Value) = False Then
                    For k = 1 To 2
                        Worksheets(assy).Cells(l, k) = Worksheets("PART LIST").Cells(j, k)
                    Next k
                        Worksheets(assy).Cells(l, 3) = Worksheets("PART LIST").Cells(j, i)
                        l = l + 1
                 End If
            Next j
                        
        Next i
End Sub




Thanks for your help in advance
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
When you get an error message, click Debug and you will see that the line causing the error highlighted. Tell us what line that is to help us diagnose the problem.
 
Upvote 0
When you get an error message, click Debug and you will see that the line causing the error highlighted. Tell us what line that is to help us diagnose the problem.
\

Thank You very much Joe.

I have found a solution.
I don't know the cause of the problem but it runs now.


Code:
assy = Worksheets("PART LIST").Cells(1, i)
                Sheets(3).Copy After:=Sheets(Sheets.Count)
                Set ws = ActiveSheet
        ws.Name = assy
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top