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
[TABLE="width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Value[/TD]
[TD]Description[/TD]
[/TR]
[TR]
[TD]z01[/TD]
[TD]APPLG[/TD]
[TD]Green apple[/TD]
[/TR]
[TR]
[TD]z02[/TD]
[TD]BNANL[/TD]
[TD]Long banana[/TD]
[/TR]
[TR]
[TD]z01[/TD]
[TD]APPLR[/TD]
[TD]Red apple[/TD]
[/TR]
[TR]
[TD]z02[/TD]
[TD]BNANS[/TD]
[TD]Short banana[/TD]
[/TR]
[TR]
[TD]z01[/TD]
[TD]APPLC[/TD]
[TD]Cooking apple[/TD]
[/TR]
</tbody>[/TABLE]

Wksht - z01
[TABLE="width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Value[/TD]
[TD]Description[/TD]
[/TR]
[TR]
[TD]z01[/TD]
[TD]APPLG[/TD]
[TD]Green apple[/TD]
[/TR]
[TR]
[TD]z01[/TD]
[TD]APPLR[/TD]
[TD]Red apple[/TD]
[/TR]
[TR]
[TD]z01[/TD]
[TD]APPLC[/TD]
[TD]Cooking apple[/TD]
[/TR]
</tbody>[/TABLE]

Wksht - z02
[TABLE="width: 500"]
<tbody>[TR]
[TD]ID[/TD]
[TD]Value[/TD]
[TD]Description[/TD]
[/TR]
[TR]
[TD]z02[/TD]
[TD]BNANL[/TD]
[TD]Long banana[/TD]
[/TR]
[TR]
[TD]z02[/TD]
[TD]BNANS[/TD]
[TD]Short banana[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
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,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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