Compare two worksheet on conditional basis

[Closed]
Report
-
 Helper -
Hello,
I have to compare two worksheets on conditional basis.
ex: worksheet1 having two columns loginname(col A) and date (col B) and worksheet2 having loginname ,date and additional columns (say colC,colD,..ColI).

If both worksheet having same loginname and date i have to copy values of worksheet2.Col C to Col I to worksheet1. col C to Col I.

Can u pls tell me how to do in VBA Script. Any help on this should be appreciated.

1 reply

Assumption:
There are no empty cells in the name column of the first worksheet you want to compare that have only the login name and dates.


Private Sub CommandButton2_Click()

Set s = Sheets("Sheet1") 'You can rename the sheets to match your sheet names
Set r = Sheets("Sheet2")
Dim i
Dim j
i = 2
j = 2

Do Until s.Range("A" & j) = ""

If s.Range("A" & i) = r.Range("A" & j) And s.Range("B" & i) = r.Range("B" & j) Then
s.Range("C" & i) = r.Range("C" & j)
s.Range("D" & i) = r.Range("D" & j)
s.Range("E" & i) = r.Range("E" & j)
s.Range("F" & i) = r.Range("F" & j)
s.Range("G" & i) = r.Range("G" & j)
s.Range("H" & i) = r.Range("H" & j)
s.Range("I" & i) = r.Range("I" & j)
End If

i = i + 1
j = j + 1

Loop

End Sub
1
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 2942 users have said thank you to us this month