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

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
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,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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