Need a Macro To export Specific sheets of excel to new file as VALUES ONLY

Hemanth Golla

New Member
Joined
Nov 29, 2022
Messages
2
Platform
  1. Windows
Currently i am using following VBA Code to export sheets. But i need the export the specific sheets as values only ( Remove formula's and links ) and Remove Sheet 1 in new file.

Option Explicit

Sub Export_Worksheets()

Dim wbSource As Workbook, wbTarget As Workbook
Dim worksheetList As String 'Use colon as seperator since you cannot have colon in your worksheet name'
Dim worksheetArr As Variant
Dim arrIndx As Long

On Error GoTo errHandle
worksheetList = "Jan:Feb:Mar:Aug"

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

Exit Sub

errHandle:
MsgBox "Error: " & Err.Description, vbExclamation
GoTo CleanObjects
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi Hemanth Golla,

how about

VBA Code:
Sub Export_Worksheets()
' https://www.mrexcel.com/board/threads/need-a-macro-to-export-specific-sheets-of-excel-to-new-file-as-values-only.1223360/

Dim wbTarget As Workbook
Dim worksheetList As String 'Use colon as seperator since you cannot have colon in your worksheet name'
Dim worksheetArr As Variant
Dim arrIndx As Long
Dim ws As Worksheet

On Error GoTo errHandle
worksheetList = "Jan:Feb:Mar:Aug"

worksheetArr = Split(worksheetList, ":")

If UBound(worksheetArr) = -1 Then Exit Sub

Worksheets(worksheetArr).Copy
Set wbTarget = ActiveWorkbook

For Each ws In wbTarget.Worksheets
  With ws.UsedRange
    .Value = .Value
  End With
Next ws

MsgBox "Export complete.", vbInformation

CleanObjects:
Set wbTarget = Nothing

Exit Sub

errHandle:
MsgBox "Error: " & Err.Description, vbExclamation
GoTo CleanObjects
End Sub

Ciao,
Holger
 
Upvote 0
Solution

Forum statistics

Threads
1,224,816
Messages
6,181,141
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