VBA -copy data from one sheet to another

Alisya

Well-known Member
Joined
Nov 27, 2008
Messages
532
Hi the below code copies data from Active worksheet "ShtSrc" and then copies to "shtDst". I would like to change the ranges it copies to shtDst, so if the data is from A2:I, i only want the code to copy A2:C and Col H and then paste this to "A6" in shtDst


Code:
With shtSrc
        Set lstRowSrc = .Cells(.Rows.Count, gColumnForLastRow).End(xlUp)
                lstSrcCellRwNum = lstRowSrc.Row
         With .Range("A2:I" & lstSrcCellRwNum)
            On Error Resume Next
                Intersect(shtDst.UsedRange, shtDst.Range("A6:I" & Rows.Count)).ClearContents
            On Error GoTo 0
            .Copy shtDst.Range("A1")
            .EntireColumn.AutoFit
         End With
    
    End With
 

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.

Alisya

Well-known Member
Joined
Nov 27, 2008
Messages
532
I tried using this

With .Range("A2:M" & lstSrcCellRwNum & ",H2:H" & lstSrcCellRwNum)

but i got an error on this line "Run time error 1004, "That command cannot be used on mutliple lines"

.Copy shtDst.Range("A6")
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,195
Messages
5,835,918
Members
430,394
Latest member
Ace_Quared

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