ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Add a Sheet From a Previous Sheet Macro (https://www.excelbanter.com/excel-worksheet-functions/118369-add-sheet-previous-sheet-macro.html)

Don

Add a Sheet From a Previous Sheet Macro
 
I have a daily reporting system in which I have a macro to make a new sheet
as well as clear some information from the previous sheet in a workbook with
muliple sheets of different names besides DR(1) etc. Since the number of days
per job is variable, I need to add something into the macro to copy the
previous day information to the new sheet instead of reverting back to the
original to make a copy of it. The macro that I use now is below and you can
see it copys DR(1) when I would like it to copy from DR(6) if that sheet
happens to be in the workbook. I'm not sure what to add in and everthing
tried to date has not worked.

Sub NewDay()

Sheets("DR(1)").Copy After:=Sheets("DR(1)")
Range("U1") = Range("U1") + 1
Range("G12:O31,Q44:V49,H47:H49,K46:K49,N46:N49").S elect
Selection.ClearContents
Range("G12").Select
End Sub:

Regards and thanks in advance.

Dave Peterson

Add a Sheet From a Previous Sheet Macro
 
How about just working against the activesheet?

So select the sheet to copy first, then run the macro.

Sheets("DR(1)").Copy After:=Sheets("DR(1)")
becomes
Activesheet.Copy After:=activesheet



Don wrote:

I have a daily reporting system in which I have a macro to make a new sheet
as well as clear some information from the previous sheet in a workbook with
muliple sheets of different names besides DR(1) etc. Since the number of days
per job is variable, I need to add something into the macro to copy the
previous day information to the new sheet instead of reverting back to the
original to make a copy of it. The macro that I use now is below and you can
see it copys DR(1) when I would like it to copy from DR(6) if that sheet
happens to be in the workbook. I'm not sure what to add in and everthing
tried to date has not worked.

Sub NewDay()

Sheets("DR(1)").Copy After:=Sheets("DR(1)")
Range("U1") = Range("U1") + 1
Range("G12:O31,Q44:V49,H47:H49,K46:K49,N46:N49").S elect
Selection.ClearContents
Range("G12").Select
End Sub:

Regards and thanks in advance.


--

Dave Peterson

Don

Add a Sheet From a Previous Sheet Macro
 
Thanks Dave. It worked like a charm. Why is the answer so obvious after
somebody give it to me!!

"Dave Peterson" wrote:

How about just working against the activesheet?

So select the sheet to copy first, then run the macro.

Sheets("DR(1)").Copy After:=Sheets("DR(1)")
becomes
Activesheet.Copy After:=activesheet



Don wrote:

I have a daily reporting system in which I have a macro to make a new sheet
as well as clear some information from the previous sheet in a workbook with
muliple sheets of different names besides DR(1) etc. Since the number of days
per job is variable, I need to add something into the macro to copy the
previous day information to the new sheet instead of reverting back to the
original to make a copy of it. The macro that I use now is below and you can
see it copys DR(1) when I would like it to copy from DR(6) if that sheet
happens to be in the workbook. I'm not sure what to add in and everthing
tried to date has not worked.

Sub NewDay()

Sheets("DR(1)").Copy After:=Sheets("DR(1)")
Range("U1") = Range("U1") + 1
Range("G12:O31,Q44:V49,H47:H49,K46:K49,N46:N49").S elect
Selection.ClearContents
Range("G12").Select
End Sub:

Regards and thanks in advance.


--

Dave Peterson


Dave Peterson

Add a Sheet From a Previous Sheet Macro
 
I guess it's the same reason it's easy to pick last week's lottery numbers!

Don wrote:

Thanks Dave. It worked like a charm. Why is the answer so obvious after
somebody give it to me!!

"Dave Peterson" wrote:

How about just working against the activesheet?

So select the sheet to copy first, then run the macro.

Sheets("DR(1)").Copy After:=Sheets("DR(1)")
becomes
Activesheet.Copy After:=activesheet



Don wrote:

I have a daily reporting system in which I have a macro to make a new sheet
as well as clear some information from the previous sheet in a workbook with
muliple sheets of different names besides DR(1) etc. Since the number of days
per job is variable, I need to add something into the macro to copy the
previous day information to the new sheet instead of reverting back to the
original to make a copy of it. The macro that I use now is below and you can
see it copys DR(1) when I would like it to copy from DR(6) if that sheet
happens to be in the workbook. I'm not sure what to add in and everthing
tried to date has not worked.

Sub NewDay()

Sheets("DR(1)").Copy After:=Sheets("DR(1)")
Range("U1") = Range("U1") + 1
Range("G12:O31,Q44:V49,H47:H49,K46:K49,N46:N49").S elect
Selection.ClearContents
Range("G12").Select
End Sub:

Regards and thanks in advance.


--

Dave Peterson


--

Dave Peterson


All times are GMT +1. The time now is 07:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com