Copy specific data from master worksheet to specific worksheet *VBA*

T44RM4R

New Member
Joined
Aug 18, 2017
Messages
1
Hi all. I have a basic understanding of Excel so please bare with me. I am trying to create a macro that will copy data from a master worksheet and paste it into a worksheet that corresponds with data ID (see example). I hope this makes sense,
Thank you
:)

Master
IDValueDescription
z01APPLGGreen apple
z02BNANLLong banana
z01APPLRRed apple
z02BNANSShort banana
z01APPLCCooking apple

<tbody>
</tbody>

Wksht - z01
IDValueDescription
z01APPLGGreen apple
z01APPLRRed apple
z01APPLCCooking apple

<tbody>
</tbody>

Wksht - z02
IDValueDescription
z02BNANLLong banana
z02BNANSShort banana

<tbody>
</tbody>
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Something like this (untested)
Assume master sheet is called "Mastersheet"

Code:
sub CopyDataById
dim inSheet as string
dim inRow,outRow as long

for inrow = 1 to 10 '(or however many rows you have)
inSheet = sheets("Mastersheet").cells(inrow,1).value 'set target worksheet based on ID
outrow = sheets(inSheet).cells("a10000").end(xlup).row+1 'find next available row in target worksheet
sheets(insheet).cells(outrow,1).value = sheets("Mastersheet").cells(inrow,1).value
sheets(insheet).cells(outrow,2).value = sheets("Mastersheet").cells(inrow,2).value
sheets(insheet).cells(outrow,3).value = sheets("Mastersheet").cells(inrow,3).value
next inRow

end sub
 
Upvote 0

Forum statistics

Threads
1,214,630
Messages
6,120,634
Members
448,973
Latest member
ChristineC

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