简体   繁体   中英

Excel vba to copy and paste a cells from different worksheets to new worksheet

i need a macro to copy and paste a certain cells(b5:d10) from multiple worksheets and paste it into a new single worksheet. just i want to collide the contents .thanks in advance

sub copyrange()
range("b5:d10).copy
range("e1").select
activesheet.paste
application.cutcopymode=false
endsub

my code doesnot copy all the worksheets data. kindly help me to copy and paste it

Sub copyrange()
    Dim rngTarget As Range, wksTemp As Worksheet

    Set rngTarget = ThisWorkbook.Worksheets(1).Range("A2:C7")

    For Each wksTemp In ActiveWorkbook.Worksheets
        rngTarget.Value = wksTemp.Range("B5:D10").Value
        Set rngTarget = rngTarget.Offset(6)
    Next wksTemp
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM