PDA

View Full Version : Macro Help



Nickerzzzzz
09-14-2015, 12:35 PM
Hi,

I have scoured the forums and blogs for something to cut/paste but nothing seems to fit the bill, I blame my inexperience in vba as I probably cant see the wood for the trees, it's right what they say if you don't use it you lose it...not that I ever had it!! ;)

Hoping that someone can educate me with a bit of code that will do the following...

I have three Worksheets and I need to copy all Rows from Worksheet 1 into Worksheet 3 where any Cell in Column E of Worksheet 2 matches any Cell in Column D of Worksheet 1.

Worksheet 1 contains duplicate Serial No's in Column D, I need All Rows (including the duplicates) copied across to Worksheet 3 where a Match is found in Column E of Worksheet 2, Column E contains no duplicates.

Worksheet 1 = Master Data (duplicate serials).
Worksheet 2 = Wanted Serials to be copied (no duplicates).
Worksheet 3 = Result.

I have uploaded an example of some random data to show what I need to do in-case my blurb is gobbledygook ;)

Many Thanks in anticipation :)

SamT
09-14-2015, 06:05 PM
See the VBA help on Find...Find Next for the Find code
For brevity of typing
Set RefRng = Sheet 2 Column E
Set SrcRng = Sheet 1 Column D
Set Sht3 Worksheet 3
Reference a variable (Nrw) to Sht3 next empty row number

For Each Cel in RefRng
'Here is where all the find code goes
Set Found = SrcRng.Find(Cel.Value)
If not Found is nothing then
Found.EntireRow.Copy Sht3.Cells(Nrw, 1)
Nrw = Nrw + 1
End If
'End Find code
Next Cel

Nickerzzzzz
09-15-2015, 01:05 AM
[QUOTE=SamT;330712]See the VBA help on Find...Find Next for the Find code

Thanks Sam, will give it a go and see if I can figure it out, need to get a few lines done quick so manually cutting and pasting until I get some free time to look at the vba help.