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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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")
 
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,636
Members
449,043
Latest member
farhansadik

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