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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,214,647
Messages
6,120,722
Members
448,987
Latest member
marion_davis

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