Copy selected columns and paste in a different worksheet

sahaider

New Member
Joined
May 30, 2014
Messages
31
Hello all,
Can anyone help me with this?
I would like to copy selected columns from a worksheet and paste it in cell A1 of another sheet.
the columns to be selected are columns B to D and column H and paste the copied contents in cell A1 of another sheet called TEST1.

Here is the code I have so far:

Range("B2:D2","H2").Select
Range(Selection, Selection.End(xlDown)).Select



Application.CutCopyMode = False
Selection.Copy

Worksheets("TEST1").Select
Range("A1").Select
ActiveSheet.Paste


The above code is not copying all the contents to the destination worksheet TEST1

Thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Saurabhj

Active Member
Joined
Jun 6, 2020
Messages
423
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi,

Quick solution -

VBA Code:
     ActiveSheet.Range("B:D").Copy Destination:=Worksheets("TEST1").Range("A1")
    ActiveSheet.Range("H:H").Copy Destination:=Worksheets("TEST1").Range("D1")

Thanks,
Saurabh
 

vcoolio

Well-known Member
Joined
Jun 29, 2014
Messages
1,079
Hello Sahaider,

Another option:-

VBA Code:
Sub Test()
        
        Dim ws1 As Worksheet: Set ws1 = Sheet1
        Dim wsT As Worksheet: Set wsT = Sheets("TEST1")
        
Application.ScreenUpdating = False

        wsT.UsedRange.Clear

        With ws1.[A1].CurrentRegion
               Union(.Columns("B:D"), .Columns("H")).Copy wsT.[A1]
        End With

Application.ScreenUpdating = True

End Sub


The code clears the "TEST1" sheet prior to each data transfer.
The code will also take the headings over to the "TEST1" sheet.
Please test it in a copy of your workbook first.

I hope that this helps.

Cheerio,
vcoolio.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,381
Messages
5,641,827
Members
417,240
Latest member
pjohnsonexcel

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
Top