VBA code for copy paste special range

pat01

New Member
Joined
Aug 2, 2009
Messages
29
Hi
I need your help please? I have a workbook "Main" with sheet "Sheet 1". I need to use VBA (command button) to copy and paste special values columns A:Z to a new workbook . The command button should be in "Main" workbook sheet "Sheet 1"
Thanks in advance
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi
Ttry

VBA Code:
Sub test()
    Dim a As Variant
    Dim wb As Workbook
    a = Cells(1, 1).CurrentRegion
    ReDim Preserve a(1 To UBound(a), 1 To 26)
    Set wb = Workbooks.Add
    wb.Sheets("sheet1").Cells(1, 1).Resize(UBound(a, 1), UBound(a, 2)) = a
End Sub
 
Upvote 0
Hi
Ttry

VBA Code:
Sub test()
    Dim a As Variant
    Dim wb As Workbook
    a = Cells(1, 1).CurrentRegion
    ReDim Preserve a(1 To UBound(a), 1 To 26)
    Set wb = Workbooks.Add
    wb.Sheets("sheet1").Cells(1, 1).Resize(UBound(a, 1), UBound(a, 2)) = a
End Sub
Hi
Ttry

VBA Code:
Sub test()
    Dim a As Variant
    Dim wb As Workbook
    a = Cells(1, 1).CurrentRegion
    ReDim Preserve a(1 To UBound(a), 1 To 26)
    Set wb = Workbooks.Add
    wb.Sheets("sheet1").Cells(1, 1).Resize(UBound(a, 1), UBound(a, 2)) = a
End Sub
It worked thanks but only the format of the cells was not copied across . In the original workbook I have filters and some highlighted fields? Also, the width of the column should stay the same.
Thanks again in advance ?
Many thanks ?
 
Upvote 0
Can we please add to the VBA code above the formatting of the cells. I need to copy also the same format of the cells that I had in my original workbook?
Thanks
 
Upvote 0

Forum statistics

Threads
1,215,368
Messages
6,124,520
Members
449,169
Latest member
mm424

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