Copying Active Sheet stops abruptly after execution without throwing any error!

sak1985

New Member
Joined
Jul 22, 2012
Messages
11
Hello All,

I am trying to copy a sheet called Temp in a workbook and pasting in the same workbook multiple times.

Code:
For oj = 2 To 21
    Application.StatusBar = "Please wait... PBA's are generating"
    If ActiveWorkbook.Sheets("Temp").Visible = True Then
        ActiveWorkbook.Sheets("Temp").Select
        [B]ActiveWorkbook.Sheets("Temp").Copy After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)[/B]
        ActiveSheet.Name = Left(Sheet2.Range("A" & oj).Value, 9)
        ActiveSheet.Range("B1").Value = Sheet2.Range("A" & oj).Value
        ActiveSheet.Range("B2").Value = "Week"
        ActiveSheet.Range("B3").Value = "% Percentage"
       End If
    Next oj

Here in the code stops at the highlighted part. What would be the issue here

Regards,
Sakthi
 
Last edited by a moderator:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
It seems to work for me, but will get caught up on the next line if there are any duplicate values in your list of sheet names. I don't see a problem with the highlighted part, though. Which error message is it giving you?
 
Upvote 0
It seems to work for me, but will get caught up on the next line if there are any duplicate values in your list of sheet names. I don't see a problem with the highlighted part, though. Which error message is it giving you?

Thanks for taking time to reply... I don't get any error during the execution, apart from that the execution gets interrupt automatically without any message. There is no duplicate sheet with the same name but the code has to replicate the sheet "Temp" n number of times specified.

Code:
If ActiveWorkbook.Sheets("Temp").Visible = True Then
        ActiveWorkbook.Sheets("Temp").Select
        [B]ActiveWorkbook.Sheets("Temp").Copy After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)
[/B]

From the above code the replication is done from "Temp" which is happening and I get a new sheet named
Temp(1).

But from the below code the sheet name has to be renamed but here the code gets interrupt without any error msg.
Code:
ActiveSheet.Name = Left(Sheet2.Range("A" & oj).Value, 9)

So, as per the above code I get only one sheet gets replicated in the name Temp(1) which is not the purpose of this code.

Regards,
Sakthi
 
Upvote 0
I don't understand how your code can be interrupted without any error message... if you run the code and it stops you at a certain line that it highlights yellow, it should pop up with an error message. What values are in Sheet2.Range("A" & oj)?
 
Upvote 0
I don't understand how your code can be interrupted without any error message... if you run the code and it stops you at a certain line that it highlights yellow, it should pop up with an error message. What values are in Sheet2.Range("A" & oj)?

Even I have the same question as If any interruption will be highlighted with an error message. The Value in Sheet2.Range("A"&oj) is the no of Sheet's to be copied.

The number of copies are passed to "oj" through a for loop.

Regards,
Sakthi
 
Upvote 0
The Value in Sheet2.Range("A"&oj) is the no of Sheet's to be copied.

Code:
ActiveSheet.Name = Left(Sheet2.Range("A" & oj).Value, 9)

Are you sure? Looks like they are values from which you are getting the first 9 characters to be the name of the active sheet...
 
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,272
Members
449,149
Latest member
mwdbActuary

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