PDA

View Full Version : Solved: New to VBA



Kmann79
12-07-2010, 07:33 AM
Can someone help on writing VBA that i would use to compare two columns on two different sheets so that when the same value is in the same columns then it prints the entire field on a seperate sheet named "Master" .
Thanks

Simon Lloyd
12-07-2010, 08:00 AM
I think you need to explain a little better but this will copy any value found on sheet1 column A that is found on sheet2 column A to sheet3 column A.
Sub Copy_If_Found()
Dim MyCell As Range, Rng As Range
Set Rng = Sheets("Sheet1").Range("A1:A" & Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row)
For Each MyCell In Rng
If Application.WorksheetFunction.CountIf(Sheets("Sheet2").Range _
("A1:A" & Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row), MyCell.Value) > 0 Then
MyCell.Copy Destination:=Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
End If
Next MyCell
End Sub

Kmann79
12-10-2010, 09:51 AM
That was was great. It gave me a great start and was able to tweak yours to resolve it.
Thanks a lot & Merry Christmas

Simon Lloyd
12-10-2010, 09:54 AM
If this is solved please visit Thread tools at the top of this window and select mark solved :)

Merry Christmas!

austenr
12-10-2010, 03:31 PM
Ill mark this solved for you.