copy problem VBA

plost33

Well-known Member
Joined
Oct 2, 2008
Messages
866
I ahve the following code that is erroring on my ".copy" line fo code. does anyone knwo why?

Code:
Sub CompleteForms()
Dim Vendor As String
Dim CurrentRow As String
Dim CurrentColumn As String
Dim PasteRangeName As String
Dim XXX As String
Dim Edate As String
    i = Sheets("data").Range("A2").End(xlDown).Row
    
     For Each cell In Sheets("data").Range("A2:R" & i)
        On Error Resume Next
        
        
        CurrentRow = Row
        Vendor = Sheets("Data").Range(A & CurrentRow)
   
        Sheets("Template").Copy After:=Sheets(2)
        Sheets("Template (2)").Name = Vendor
    
        CurrentColumn = Column
        PasteRangeName = Sheets("data").Range(CurrentColumn & "1").Value
        
        .Copy
        Sheets(Vendor).Range(PasteRangeName).PasteSpecial xlValue
        
        Edate = Sheets(Vendor).Range(Edate).Value
        XXX = Format(Edate, "[$-409]ddmmmyyyy;@")
        
        
        
    Next
    
     Folder = "C:\Users\tphythian\Documents\Vendor Evaluations"
     ThisWorkbook.Worksheets(Vendor).Copy
        With ActiveSheet.UsedRange
            .Value = .Value
        End With
        With ActiveWorkbook
            .SaveAs Folder & "\" & Vendor & " - " & XXX & ".xlsx"
            .Close
        End With
         
    
    Sheets(Vendor).Delete
    
   
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
alright, so i got one more problem, as i see it...

Code:
Sub CompleteForms()
Dim Vendor As String
Dim Vendor1 As String
Dim CurrentRow As String
Dim CurrentColumn As Long
Dim PasteRangeName As String
Dim XXX As String
Dim Edate As String
    i = Sheets("data").Range("A2").End(xlDown).Row
    
     For Each cell In Sheets("data").Range("A2:R" & i)
        'On Error Resume Next
        
        Sheets("Template").Copy After:=Sheets(2)
        CurrentRow = cell.Row
        Vendor1 = Sheets("Data").Range("B" & CurrentRow)
        Vendor = Left(Vendor1, 12)
        Sheets("Template (2)").Name = Vendor
        
        CurrentColumn = cell.Column
        PasteRangeName = Sheets("data").Cells(1, CurrentColumn).Value
        
        cell.Copy
        Sheets(Vendor).Range(PasteRangeName).PasteSpecial xlValue
        
        
        If CurrentColumn = 18 Then
        
            Edate = Sheets(Vendor).Range(Edate).Value
            XXX = Format(Edate, "[$-409]ddmmmyyyy;@")
            
            Folder = "C:\Users\tphythian\Documents\Vendor Evaluations"
            ThisWorkbook.Worksheets(Vendor).Copy
            
                With ActiveSheet.UsedRange
                    .Value = .Value
                End With
                
                With ActiveWorkbook
                    .SaveAs Folder & "\" & Vendor & " - " & XXX & ".xlsx"
                    .Close
                End With
                
            Sheets(Vendor).Delete
                
       Else
       
    Next
        
       
End Sub



i am getting an error saying: "Next without For". i do have a for...is there a problem with my if statement?
 
Upvote 0
andrew, i am getting ask if i want to delete each sheet when the following line of code runs:

Sheets(Vendor).Delete


how do i get that to just delete the sheet without asking me?
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,507
Members
452,917
Latest member
MrsMSalt

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