Hi,
I am trying to update a report with a list of cost centres and copy each report created to a new tab.
The sheets in my workbook are called:
The steps I am trying to code into a for next loop are as follows:
Code for the For Next Loop
Dim Col As Integer
For Row = 1 To 9
Set i = Sheets("CCList").Cells(Row, 1)
Sheets("CCREP").Range("A8").Value = i
Call Copysheet
Next Row
Please note the sample cost centre codes are in sheet CCREP, cells A1 to A9
Code for Copying to a New Tab
Sub Copysheet()
Dim MyDate As String
Dim CC As Range
MyDate = Format(Now, "mm-ss")
Set CC = Sheets("CCLIST").Range("A8")
Sheets("CCREP").Copy After:=Sheets("CCREP")
Sheets("CCREP (2)").Name = CC & " | " & MyDate
With Sheets(CC & " | " & MyDate)
.Unprotect
.Cells.Copy
.Cells.PasteSpecial xlValues
End With
Range("A8").Select
SendKeys "{ESC}", True
Sheets("CCREP").Activate
End Sub
This bit of code works just fine
Overview
The issue that I have is that both parts work until I call the copysheet module and then the vba crashes.
I don't understant the error???
What i was expecting from this code was the following:
This is not the case and if anyone can solve this problem, explain why it will not work, or point me in the right direction I will be very greatful.
Thank you in advance.
Matt
I am trying to update a report with a list of cost centres and copy each report created to a new tab.
The sheets in my workbook are called:
- CC List
- CC REP
The steps I am trying to code into a for next loop are as follows:
- update a specific cell (criteria key for a sum if) on CC REP sheet with a list of cost centre codes from another (one code at a time).
- Copy the report that the updated cell drives into a new tab
Code for the For Next Loop
Dim Col As Integer
For Row = 1 To 9
Set i = Sheets("CCList").Cells(Row, 1)
Sheets("CCREP").Range("A8").Value = i
Call Copysheet
Next Row
Please note the sample cost centre codes are in sheet CCREP, cells A1 to A9
Code for Copying to a New Tab
Sub Copysheet()
Dim MyDate As String
Dim CC As Range
MyDate = Format(Now, "mm-ss")
Set CC = Sheets("CCLIST").Range("A8")
Sheets("CCREP").Copy After:=Sheets("CCREP")
Sheets("CCREP (2)").Name = CC & " | " & MyDate
With Sheets(CC & " | " & MyDate)
.Unprotect
.Cells.Copy
.Cells.PasteSpecial xlValues
End With
Range("A8").Select
SendKeys "{ESC}", True
Sheets("CCREP").Activate
End Sub
This bit of code works just fine
Overview
The issue that I have is that both parts work until I call the copysheet module and then the vba crashes.
I don't understant the error???
What i was expecting from this code was the following:
- CC codes passed to CCREP sheet in cell A8
- The sheet copied to a new tab as paste special values, and tab renamed as the cost centre code
- The next cycle of the loop to continue
This is not the case and if anyone can solve this problem, explain why it will not work, or point me in the right direction I will be very greatful.
Thank you in advance.
Matt