E
Edgar
Hi
Can anyone suggest anything that I could do to the
following code to improve the efficiency of it as it is
running quite slow at the moment.
It copies values from separate sheets onto a template file
and then save as the template file.
TIA
Sub Create_Remittance()
Dim i As Integer
Dim sh As Worksheet
Dim File_Name As Workbook
Dim outfile As Workbook
Dim file_path As String
'Copies all values from sheets(sh) to Template file
For i = 5 To Sheets.Count
Set sh = Sheets(i)
sh.Activate
File_Name = ActiveWorkbook.Worksheets("Menu").Cells.Range
("D9").Value
Set outfile = Workbooks.Open(File_Name)
Windows("AU Remittance Module").Activate
file_path = Worksheets("Menu").Range("D12")
Range("B1").Copy
outfile.Worksheets("Remittance").Range("C6").PasteSpecial
Paste:=xlValues
Range("A1").Copy
outfile.Worksheets("Remittance").Range("C4").PasteSpecial
Paste:=xlValues
Range("C1").Copy
outfile.Worksheets("Remittance").Range("C8").PasteSpecial
Paste:=xlValues
Range("E1").Copy
outfile.Worksheets("Remittance").Range("C10").PasteSpecial
Paste:=xlValues
Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row).Copy
outfile.Worksheets("Remittance").Range("A16").PasteSpecial
Paste:=xlValues
Range("D1" & Cells(Rows.Count, 1).End(xlUp).Row).Copy
outfile.Worksheets("Remittance").Range("D16").PasteSpecial
Paste:=xlValues
Range("G1:G" & Cells(Rows.Count, 1).End(xlUp).Row).Copy
outfile.Worksheets("Remittance").Range("C16").PasteSpecial
Paste:=xlValues
Range("H1:H" & Cells(Rows.Count, 1).End(xlUp).Row).Copy
outfile.Worksheets("Remittance").Range("E16").PasteSpecial
Paste:=xlValues
outfile.Activate
Supp_Name = Range("C8")
Trans_No = Range("C10")
Supp_id = Range("C6")
Payment_Date = Range("c4")
Remit_Name = file_path & "\" & Supp_id & " " & Trans_No
& " " & Format(Payment_Date, "ddmmmyy") & ".xls"
ActiveWorkbook.SaveAs Remit_Name
ActiveWorkbook.Close
Next i
ActiveWorkbook.Sheets("Menu").Select
End Sub
Can anyone suggest anything that I could do to the
following code to improve the efficiency of it as it is
running quite slow at the moment.
It copies values from separate sheets onto a template file
and then save as the template file.
TIA
Sub Create_Remittance()
Dim i As Integer
Dim sh As Worksheet
Dim File_Name As Workbook
Dim outfile As Workbook
Dim file_path As String
'Copies all values from sheets(sh) to Template file
For i = 5 To Sheets.Count
Set sh = Sheets(i)
sh.Activate
File_Name = ActiveWorkbook.Worksheets("Menu").Cells.Range
("D9").Value
Set outfile = Workbooks.Open(File_Name)
Windows("AU Remittance Module").Activate
file_path = Worksheets("Menu").Range("D12")
Range("B1").Copy
outfile.Worksheets("Remittance").Range("C6").PasteSpecial
Paste:=xlValues
Range("A1").Copy
outfile.Worksheets("Remittance").Range("C4").PasteSpecial
Paste:=xlValues
Range("C1").Copy
outfile.Worksheets("Remittance").Range("C8").PasteSpecial
Paste:=xlValues
Range("E1").Copy
outfile.Worksheets("Remittance").Range("C10").PasteSpecial
Paste:=xlValues
Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row).Copy
outfile.Worksheets("Remittance").Range("A16").PasteSpecial
Paste:=xlValues
Range("D1" & Cells(Rows.Count, 1).End(xlUp).Row).Copy
outfile.Worksheets("Remittance").Range("D16").PasteSpecial
Paste:=xlValues
Range("G1:G" & Cells(Rows.Count, 1).End(xlUp).Row).Copy
outfile.Worksheets("Remittance").Range("C16").PasteSpecial
Paste:=xlValues
Range("H1:H" & Cells(Rows.Count, 1).End(xlUp).Row).Copy
outfile.Worksheets("Remittance").Range("E16").PasteSpecial
Paste:=xlValues
outfile.Activate
Supp_Name = Range("C8")
Trans_No = Range("C10")
Supp_id = Range("C6")
Payment_Date = Range("c4")
Remit_Name = file_path & "\" & Supp_id & " " & Trans_No
& " " & Format(Payment_Date, "ddmmmyy") & ".xls"
ActiveWorkbook.SaveAs Remit_Name
ActiveWorkbook.Close
Next i
ActiveWorkbook.Sheets("Menu").Select
End Sub