VBA - Copy Sheet2 to new workbook without formulas

zepharoz

New Member
Joined
Jul 5, 2023
Messages
11
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
Platform
  1. Windows
Hi, been trying to figure out why it doesn't work and honestly need the help in case I go insane from this. Sheet1 contains some data but irrelevant and a Button for which runs the code. Sheet2 contains all the formulas, formatting, and heading. Goal is to press button in sheet1, which runs the code that copies sheet2 into a new workbook without any formulas but retains formatting. Code is:

Private Sub CommandButton1_Click()

Sheets("Sheet2").Copy

Cells.Copy
Range("A1").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False

End Sub


Thanks in advance.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Try the following with a copy of your workbook
VBA Code:
Private Sub CommandButton1_Click()
    Sheets("Sheet2").Copy
    With ActiveSheet.UsedRange
        .Value = .Value
    End With
End Sub
 
Upvote 1
Solution
Try the following with a copy of your workbook
VBA Code:
Private Sub CommandButton1_Click()
    Sheets("Sheet2").Copy
    With ActiveSheet.UsedRange
        .Value = .Value
    End With
End Sub
I don't know what magic you used, but it works. Can you tell me why my code didn't work or why yours did? Thanks a million.
 
Upvote 0
Not sure why yours didn't work - it does a very similar thing in a different way (although yours selects the entire sheet v just the used range).
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,958
Members
449,096
Latest member
Anshu121

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