Copy data from worksheet and paste in same worksheet but at different range

adpatel

New Member
Joined
May 30, 2019
Messages
42
Office Version
  1. 2016
Platform
  1. Windows
I have some data points that are unique in each sheet and the same unique data points need to pasted as a value in the same worksheet but at different range

I have write down following VBA code for copy paste in same sheet

Code:
[COLOR=#101094][FONT=Consolas][FONT=inherit]Sub[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit] EOD[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]()[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]

[/FONT][/FONT][/COLOR][COLOR=#101094][FONT=Consolas][FONT=inherit]Dim[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit] i [/FONT][/FONT][/COLOR][COLOR=#101094][FONT=Consolas][FONT=inherit]As[/FONT][/FONT][/COLOR][COLOR=#101094][FONT=Consolas][FONT=inherit]Long[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]

[/FONT][/FONT][/COLOR][COLOR=#101094][FONT=Consolas][FONT=inherit]For[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit] i [/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]=[/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]4[/FONT][/FONT][/COLOR][COLOR=#101094][FONT=Consolas][FONT=inherit]To[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit] ThisWorkbook[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit].[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]Worksheets[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit].[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]Count

Range[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]([/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]"B11:G150"[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]).[/FONT][/FONT][/COLOR][COLOR=#101094][FONT=Consolas][FONT=inherit]Select[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]
Selection[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit].[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]Copy
Range[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]([/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]"AA11"[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]).[/FONT][/FONT][/COLOR][COLOR=#101094][FONT=Consolas][FONT=inherit]Select[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]
Selection[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit].[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]PasteSpecial Paste[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]:=[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]xlPasteValues[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit],[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit] Operation[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]:=[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]xlNone[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit],[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit] SkipBlanks _
[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]:=[/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]False[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit],[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit] Transpose[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]:=[/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]False[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]
Range[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]([/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]"Q11:V150"[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]).[/FONT][/FONT][/COLOR][COLOR=#101094][FONT=Consolas][FONT=inherit]Select[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]
Application[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit].[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]CutCopyMode [/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]=[/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]False[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]
Selection[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit].[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]Copy
Range[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]([/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]"AG11"[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]).[/FONT][/FONT][/COLOR][COLOR=#101094][FONT=Consolas][FONT=inherit]Select[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]
Selection[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit].[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]PasteSpecial Paste[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]:=[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]xlPasteValues[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit],[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit] Operation[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]:=[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]xlNone[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit],[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit] SkipBlanks _
[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]:=[/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]False[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit],[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit] Transpose[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]:=[/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]False[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]
Application[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit].[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]CutCopyMode [/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]=[/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]False[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]
Range[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]([/FONT][/FONT][/COLOR][COLOR=#7D2727][FONT=Consolas][FONT=inherit]"AA13"[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]).[/FONT][/FONT][/COLOR][COLOR=#101094][FONT=Consolas][FONT=inherit]Select[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]

[/FONT][/FONT][/COLOR][COLOR=#101094][FONT=Consolas][FONT=inherit]Next[/FONT][/FONT][/COLOR][COLOR=#303336][FONT=Consolas][FONT=inherit]

[/FONT][/FONT][/COLOR][COLOR=#101094][FONT=Consolas][FONT=inherit]End[/FONT][/FONT][/COLOR][COLOR=#101094][FONT=Consolas][FONT=inherit]Sub[/FONT][/FONT][/COLOR][COLOR=#242729][FONT=Arial][FONT=inherit]

[/FONT][/FONT][/COLOR]


but this code copied data from sheet number 4 and pasted in other sheets
what I was trying in above code is, copy data from range "B11:G150" and paste it in same worksheet in cell "AA11" and further copy data from range "Q11:V150" and paste it in same worksheet in cell "AG11"
this loop should be start after sheet number 3(from sheet no.4) and run up to last sheet

kindly help with this. thnx

 

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.
Assuming your sheet tabs are in ascending order:
Code:
Sub EOD()
Dim i As Long
For i = 4 To ThisWorkbook.Worksheets.Count
    With Sheets(i)
        .Range("B11:G150").Copy
        .Range("AA11").PasteSpecial Paste:=xlPasteValues
        .Range("Q11:V150").Copy
        .Range("AG11").PasteSpecial Paste:=xlPasteValues
    End With
Next i
Application.CutCopyMode = False
End Sub
 
Upvote 0
It works very well, thank you for helping me out @joe
 
Upvote 0

Forum statistics

Threads
1,214,812
Messages
6,121,704
Members
449,048
Latest member
81jamesacct

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