VBA copy active worksheet as values only

MartinL

Well-known Member
Joined
Oct 16, 2008
Messages
1,141
Office Version
  1. 365
Platform
  1. Windows
Hi

I have been using the following code to save a worksheet onto a new drive whenever the workbook is closed.

I want to modify this VBA
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)

    Application.DisplayAlerts = False
    Worksheets("Gross Sales Value").Copy
    Set wbNew = ActiveWorkbook
    wbNew.SaveAs "L:\Performance Data\UK Sales\Sales (Latest).xls"
    wbNew.Close True
    Application.DisplayAlerts = True
    
End Sub

So it make a values only sheet. Is this possible?

Martin
 
Norie/Peter

Thanks for your help

I changed the code to Nories idea and it now works again.
I say "again", as I'm sure it worked when I left it last time using Peters code.

Thanks Guys

Martin
 
Upvote 0

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi Guys,

i did some modification where i wanted to copy numbers of worksheet and paste as value only, but with the following VB it will copy along the formulas.

Sub Result()
Dim wbNew As Workbook
Application.DisplayAlerts = False
Worksheets(Array("Summary", "LNBTS", "LNCEL", "LNHOIF", "LNHOW", "IRFIM", _
"UFFIM", "LNADJ", "LNADJW", "RNFC", "WCEL", "HOPL", "ADJL")).Copy
Set wbNew = ActiveWorkbook


With wbNew

With .Worksheets(1).UsedRange
.Value = .Value
End With

.SaveAs "C:\Result.xlsx"



End With

Application.DisplayAlerts = True


'
End Sub
 
Upvote 0
You are copying 13 sheets and only replacing formulas with values in the first worksheet.
 
Upvote 0
You are copying 13 sheets and only replacing formulas with values in the first worksheet.

Hi,

How do the VB looks like for copying all sheets? Does it looks like following:

Sub Result()
Dim wbNew As Workbook
Application.DisplayAlerts = False
Worksheets(Array("Summary", "LNBTS", "LNCEL", "LNHOIF", "LNHOW", "IRFIM", _
"UFFIM", "LNADJ", "LNADJW", "RNFC", "WCEL", "HOPL", "ADJL")).Copy
Set wbNew = ActiveWorkbook


With wbNew

With .Worksheets(13).UsedRange
.Value = .Value
End With

.SaveAs "C:\Result.xlsx"



End With

Application.DisplayAlerts = True


'
End Sub


thank you
 
Upvote 0
Maybe this UNTESTED
Code:
Sub mykl1()
Dim wbNew As Workbook, ws As Worksheet, myarray As Variant
Application.DisplayAlerts = False
myarray = Array("Sheet1", "Sheet2", "Sheet3")
Set wbNew = ActiveWorkbook
For Each ws In Sheets(myarray)
With ws
.UsedRange.Value = .UsedRange.Value
End With
Next ws
wbNew.SaveAs "C:\Result.xlsx"
Application.DisplayAlerts = True


'
End Sub
 
Upvote 0
Try

Rich (BB code):
Private Sub Workbook_BeforeClose(Cancel As Boolean)

    Application.DisplayAlerts = False
    Worksheets("Gross Sales Value").Copy
   With ActiveSheet.UsedRange
        .Value = .Value
    End With
    Set wbNew = ActiveWorkbook
    wbNew.SaveAs "L:\Performance Data\UK Sales\Sales (Latest).xls"
    wbNew.Close True
    Application.DisplayAlerts = True
    
End Sub

4 years hence and still paying dividends.

Thank you.
 
Upvote 0
Hello - How can you create a macro to select a date range from a slicer. For example i want t h emacro to select the past seven days from today's date. Thanks you
 
Upvote 0
@Adam
This is a very old post.
I'd suggest creating a new thread to get maximum exposure for your question !
 
Upvote 0

Forum statistics

Threads
1,215,692
Messages
6,126,232
Members
449,303
Latest member
grantrob

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