Hi Everybody . I am trying to do the following : If column X in excel 1 is not 00.00.00 , then vlookup data from sheet 1 with data in sheet based on following criteria :
if value in column 1,3,7,14,28,51 in sheet 1 = value in column 1,3,7,14,28,51 , ignore the lines
but if one of the criteria differ from the second sheet , the line should be kept . The code : Sub Check()
Dim Sheet1 As Worksheet
Dim Sheet2 As Worksheet
Set Sheet2 = Worksheets("xxx")
Dim Sheet3 As Worksheet
Set Sheet3 = Worksheets("xxxx")
Workbooks.Open Filename:="xxx"
Set Sheet1 = Workbooks("x").Worksheets(xx"Sheet1")
Sheet3.Activate
Dim off
off = 2
Dim off2
off2 = 3
Dim off3
off3 = 0
Dim Found
Found = 0
Sheet3.Range("Ax:AYxxx").Clear
Do Until Sheet1.Cells(off, 1) = ""
If (Sheet1.Cells(off, 28) <> "00:00:00") Then
Do Until (Sheet2.Cells(off2, 1) = "" Or Found = 1)
If (Sheet1.Cells(off, 1).Value = Sheet2.Cells(off2, 1).Value And Sheet1.Cells(off, 3).Value = Sheet2.Cells(off2, 3).Value And Sheet1.Cells(off, 7).Value = Sheet2.Cells(off2, 7).Value And Sheet1.Cells(off, 14).Value = Sheet2.Cells(off2, 14).Value And Sheet1.Cells(off, 43).Value = Sheet2.Cells(off2, 43).Value And Sheet1.Cells(off, 51).Value = Sheet2.Cells(off2, 51).Value And Sheet1.Cells(off, 28).Value=Sheet2.Cells(off2, 28).Value ) Then
Found = 1
End If
off2 = off2 + 1
Loop
If (Found = 0) Then
off3 = off3 + 1
For j = 1 To 51
Sheet3.Cells(off3, j) = Sheet1.Cells(off, j).Value
Next j
End If
End If
off = off + 1
off2 = 3
Found = 0
Loop
Workbooks("xxx").Close SaveChanges:=False
End Sub
Thank you for your help
if value in column 1,3,7,14,28,51 in sheet 1 = value in column 1,3,7,14,28,51 , ignore the lines
but if one of the criteria differ from the second sheet , the line should be kept . The code : Sub Check()
Dim Sheet1 As Worksheet
Dim Sheet2 As Worksheet
Set Sheet2 = Worksheets("xxx")
Dim Sheet3 As Worksheet
Set Sheet3 = Worksheets("xxxx")
Workbooks.Open Filename:="xxx"
Set Sheet1 = Workbooks("x").Worksheets(xx"Sheet1")
Sheet3.Activate
Dim off
off = 2
Dim off2
off2 = 3
Dim off3
off3 = 0
Dim Found
Found = 0
Sheet3.Range("Ax:AYxxx").Clear
Do Until Sheet1.Cells(off, 1) = ""
If (Sheet1.Cells(off, 28) <> "00:00:00") Then
Do Until (Sheet2.Cells(off2, 1) = "" Or Found = 1)
If (Sheet1.Cells(off, 1).Value = Sheet2.Cells(off2, 1).Value And Sheet1.Cells(off, 3).Value = Sheet2.Cells(off2, 3).Value And Sheet1.Cells(off, 7).Value = Sheet2.Cells(off2, 7).Value And Sheet1.Cells(off, 14).Value = Sheet2.Cells(off2, 14).Value And Sheet1.Cells(off, 43).Value = Sheet2.Cells(off2, 43).Value And Sheet1.Cells(off, 51).Value = Sheet2.Cells(off2, 51).Value And Sheet1.Cells(off, 28).Value=Sheet2.Cells(off2, 28).Value ) Then
Found = 1
End If
off2 = off2 + 1
Loop
If (Found = 0) Then
off3 = off3 + 1
For j = 1 To 51
Sheet3.Cells(off3, j) = Sheet1.Cells(off, j).Value
Next j
End If
End If
off = off + 1
off2 = 3
Found = 0
Loop
Workbooks("xxx").Close SaveChanges:=False
End Sub
Thank you for your help