Copy CF over to brand new workbook

Darren_workforce

Board Regular
Joined
Oct 13, 2022
Messages
128
Office Version
  1. 365
Platform
  1. Windows
Below are the 2 codes I've attempted to use. Neither seems to work. I just need to copy the data from my macro workbook, generate a new blank workbook, and paste the data into that new workbook but include the conditional formatting that I have applied on the macro workbook. I have searched and searched and have tried many variations of code. I've rearrange the .PasteSpecial lines multiple ways as well but nothing seems to work.

VBA Code:
Sub newWorkbook()

Worksheets("PROD Raw").Activate
Range("A1:AJ200").Copy
Workbooks.Add
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial xlPasteFormats
Selection.PasteSpecial Paste:=xlPasteColumnWidths
Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
        , SkipBlanks:=False, Transpose:=False
End Sub

VBA Code:
Sub copy_2()
Worksheets("PROD Raw").Activate
Range("A1:AJ200").Copy
Set new_workbook = Workbooks.Add()
    new_workbook.Activate
    With Range("A1")
.PasteSpecial xlPasteAll
.PasteSpecial xlPasteFormats
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteColumnWidths
    End With
End Sub
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Maybe....
Code:
Dim Ofsobj as Object
Set Ofsobj = CreateObject("Scripting.FilesystemObject")
Ofsobj.CopyFile ThisWorkbook.FullName, _
     ThisWorkbook.Path & "\" & "COPY" & ThisWorkbook.Name, True
Set Ofsobj = Nothing
Which will copy your wb to the same directory with the name COPY and your wb name. The new wb will contain everything including your conditional formatting. You can then clear the contents of any cells you don't want data for. Not sure if this is useable in your situation but it would maintain your conditional formatting. HTH. Dave
 
Upvote 0
Maybe....
Code:
Dim Ofsobj as Object
Set Ofsobj = CreateObject("Scripting.FilesystemObject")
Ofsobj.CopyFile ThisWorkbook.FullName, _
     ThisWorkbook.Path & "\" & "COPY" & ThisWorkbook.Name, True
Set Ofsobj = Nothing
Which will copy your wb to the same directory with the name COPY and your wb name. The new wb will contain everything including your conditional formatting. You can then clear the contents of any cells you don't want data for. Not sure if this is useable in your situation but it would maintain your conditional formatting. HTH. Dave
I'm not certain if I should be adding that below my current lines or run it as its own macro. Getting a Run time error '53' when I try and run it. The current filename is "Macro-New Production Report.xlsm". Maybe I'm entering it incorrectly.
 
Upvote 0
So most of my conditional formatting (color and cell shading) for sheet "PROD Raw" are based on formulas from a different worksheet "Instructions" in my macro workbook. There are 11 CF rules in all. When I run the macro and copy the information then paste it into a new workbook, only 3 of the CF rules carry over. Not sure why since I have the PasteSpecial lines included.
 
Upvote 0
Hi Darren. It's a stand alone macro. Run it by itself to produce an exact copy of your wb. You don't need to copy and paste anything... just remove the stuff that U don't want in the COPY wb was the original thought. That should maintain your formatting. Dave
 
Upvote 0
Oh gotcha. Thank you! Something just wasn't working so I added the reference data to the page that I was copying. That way, once I created the new workbook and pasted everything over, the CF (and reference information - which was hidden way off to the side in white font) carried over with it.

I appreciate the help immensely Dave. My issue has now been resolved though.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,493
Messages
6,125,128
Members
449,206
Latest member
burgsrus

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