Duplicate sheets to new workbook - Only showing values of sheet

Lee Rabbit

New Member
Joined
Apr 30, 2020
Messages
43
Office Version
  1. 2010
Platform
  1. Windows
Hi Guys,

I need a tweak on the code below. It does what I initially wanted but now I only want the contents of the duplicated sheets to show the values.

At present it is showing formula linked back to the original spreadsheet. I want to rid the new workbook of the formulas.

Please see my code below.

Regards and thanks in advance for your help.
Lee

VBA Code:
Sub Duplicate_Workbook()

    ActiveWorkbook.Sheets(Array("INVOICE 1", "INVOICE 2", "INVOICE 3")).Copy
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:="c:\PDF\test.xlsx", FileFormat:=xlOpenXMLWorkbook
    Application.DisplayAlerts = True
    ActiveWorkbook.Close

End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
How about
VBA Code:
Sub Duplicate_Workbook()
   Dim ws As Worksheet
   
   ActiveWorkbook.Sheets(Array("INVOICE 1", "INVOICE 2", "INVOICE 3")).Copy
   For Each ws In ActiveWorkbook.Worksheets
      ws.UsedRange.Value = ws.UsedRange.Value
   Next ws
   Application.DisplayAlerts = False
   ActiveWorkbook.SaveAs Filename:="c:\PDF\test.xlsx", FileFormat:=xlOpenXMLWorkbook
   Application.DisplayAlerts = True
   ActiveWorkbook.Close

End Sub
 
Upvote 0
Solution
How about
VBA Code:
Sub Duplicate_Workbook()
   Dim ws As Worksheet
  
   ActiveWorkbook.Sheets(Array("INVOICE 1", "INVOICE 2", "INVOICE 3")).Copy
   For Each ws In ActiveWorkbook.Worksheets
      ws.UsedRange.Value = ws.UsedRange.Value
   Next ws
   Application.DisplayAlerts = False
   ActiveWorkbook.SaveAs Filename:="c:\PDF\test.xlsx", FileFormat:=xlOpenXMLWorkbook
   Application.DisplayAlerts = True
   ActiveWorkbook.Close

End Sub
Thanks Fluff, worked a treat
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
You're welcome & thanks for the feedback.
Hi Fluff,

I have just noticed that when I copy the sheets to the new workbook, a few cells are reporting the error "number stored as text". These cells were previously formatted as currency and whilst I right click on them and view format, they are still showing as formatted as currency.

Is there a quick fix I can add to the code above to prevent this happening as I would like to see the finished article without the cell error.

Thanks for your patience.
Lee
 
Upvote 0
That shouldn't happen, are you sure they were numbers & not text before hand?
 
Upvote 0
That shouldn't happen, are you sure they were numbers & not text before hand?
I think I have identified the problem. On the original sheet I was using an ISBLANK formula and rather than setting it to 0.00 the cell reference is putting a £ sign in the cell. I believe this is the conflict as if the preceding cell is blank, it populates as £0.00. I have tested since and it looks like it is copying OK now. Thanks again for your help.
 
Upvote 0
Glad you sorted it & thanks for the feedback.
 
Upvote 0
Hi Fluff, sorry to bother you.

I made some amendments to the code see below of which I am happy with, however, I am trying to include a couple of sheets from external workbooks that are located in the same folder as the original. Workbooks are named "EXPORT 1" sheet name "TEST 1" and "EXPORT 2" sheet name "TEST 2".

Is there a way to merge this action into the existing code?

Thanks in advance.
Lee

VBA Code:
Sub Duplicate_Workbook()

Dim ws As Worksheet
Dim strFileName As String

    strFileName = InputBox("Type a name for the new workbook", "File Name")
    If Trim(strFileName) = vbNullString Then Exit Sub
    
    ActiveWorkbook.Sheets(Array("INVOICE 1", "INVOICE 2", "INVOICE 3", "INVOICE 4", "INVOICE 5", "INVOICE 6", "INVOICE 7")).Copy
    
    For Each ws In ActiveWorkbook.Worksheets
    
        ws.UsedRange.Value = ws.UsedRange.Value
        ws.Rows(3).Delete
        ws.Shapes("CopyRow").Delete
        ws.Shapes("SortDrivers").Delete
        ws.Shapes("DeleteENTRY").Delete
        
    Next ws
    
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename:="C:\PDF\" & strFileName & ".xlsx", FileFormat:=xlOpenXMLWorkbook
    Application.DisplayAlerts = True
    ActiveWorkbook.Close
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,241
Members
449,075
Latest member
staticfluids

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