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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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,224,586
Messages
6,179,707
Members
452,939
Latest member
WCrawford

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