exporting multiple sheets to new workbook as values and source formatting

psg2002

New Member
Joined
Feb 14, 2021
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hi,
I am able to run my VBA code smoothly. However, I am not sure how to paste them as values and keep the source formatting.

VBA Code:
Sub ExportWorksheets()
    
    Dim wbSource As Workbook, wbTarget As Workbook
    Dim worksheetList As String 
    Dim worksheetArr As Variant
    Dim arrIndx As Long


    worksheetList = "GOOGL:TSLA"
    
    worksheetArr = Split(worksheetList, ":")
    
    If UBound(worksheetArr) = -1 Then Exit Sub
    
    Set wbSource = ThisWorkbook
    
    Set wbTarget = Workbooks.Add
    
    For arrIndx = LBound(worksheetArr) To UBound(worksheetArr)
    ThisWorkbook.Worksheets(worksheetArr(arrIndx)).Copy wbTarget.Worksheets(wbTarget.Worksheets.Count)
    
    Next arrIndx
    
     MsgBox "Export complete.", vbInformation
    
CleanObjects:
    Set wbTarget = Nothing
    Set wbSource = Nothing


End Sub

I appreciate your help in advanced!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I believe this reference will solve your problem

 
Upvote 0
I believe this reference will solve your problem

My code stops at the following red line :( not sure what i am doing wrong
Rich (BB code):
Sub ExportWorksheets()
   
    Dim wbSource As Workbook, wbTarget As Workbook
    Dim worksheetList As String
    Dim worksheetArr As Variant
    Dim arrIndx As Long


    worksheetList = "GOOGL:TSLA"
   
    worksheetArr = Split(worksheetList, ":")
   
    If UBound(worksheetArr) = -1 Then Exit Sub
   
    Set wbSource = ThisWorkbook
   
    Set wbTarget = Workbooks.Add
   
    For arrIndx = LBound(worksheetArr) To UBound(worksheetArr)
    ThisWorkbook.Worksheets(worksheetArr(arrIndx)).Copy wbTarget.Worksheets(wbTarget.Worksheets.Count)
    wbtarget.worksheets(worksheetarr(arrindx).PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False

    Next arrIndx
   
     MsgBox "Export complete.", vbInformation
   
CleanObjects:
    Set wbTarget = Nothing
    Set wbSource = Nothing


End Sub
 
Upvote 0
Looking at this section:

For arrIndx = LBound(worksheetArr) To UBound(worksheetArr)
ThisWorkbook.Worksheets(worksheetArr(arrIndx)).Copy wbTarget.Worksheets(wbTarget.Worksheets.Count)
wbtarget.worksheets(worksheetarr(arrindx).PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone, SkipBlanks:=False

The Bold Red command is already paste destination. Then on the next line you were pasting again. The Bold RED line should not be there.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

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