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
 

Some videos you may like

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

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")
 

Watch MrExcel Video

Forum statistics

Threads
1,122,481
Messages
5,596,396
Members
414,063
Latest member
N_Bates

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