U
Utkarsh
Hi
Currently I am using Excel to compare two datasets like
Sheet Sheet1
Name Date Type Amount
arc 01-01-2010 x 100
b 01-01-2007 y 25
a 01-03-2008 x 124
a 01-03-2010 x 76
and
Sheet Sheet2
Name Date Type Amount
arc ltd 01-01-2010 x 100
b 01-01-2007 y 20
a 01-03-2008 x 124
d 01-05-2007 x 100
a 01-02-2010 x 76
arc 01-01-2010 x 100
and generating an output like below in Sheet2
Name Date Type Amount All All but Value All but date All but name
Original value Original date Original Name
arc ltd 01-01-2010 x 100 $A$2 arc
b 01-01-2007 y 20 $A$3 25
a 01-03-2008 x 124 $A$4
d 01-05-2007 x 100
a 01-02-2010 x 76 $A$5 01-03-2010
arc 01-01-2010 x 100 $A$2
Wtih nerly 20,000 rows Excel takes a large amount of time to process
this. I m told that this can be done very fast with Access. The row
locations can be substituted by record number as track. Please advise
as to how I cn go about doing this in Access.
My VBA code for ready reference:
*************
Sub compare()
'clear columne
Sheets("Sheet2").Range("E2:K65536").ClearContents
'Find the last row to be evaluated for each sheet
Sheets("Sheet1").Select
lastrow1 = Range("A65536").End(xlUp).Row
Sheets("Sheet2").Select
lastrow2 = Range("A65536").End(xlUp).Row
Sheets("Sheet1").Select
For i = 2 To lastrow1
'Transfer each foled for a row into a variable
rec1 = Sheets("Sheet1").Cells(i, 1).Value
rec2 = Sheets("Sheet1").Cells(i, 2).Value
rec3 = Sheets("Sheet1").Cells(i, 3).Value
rec4 = Sheets("Sheet1").Cells(i, 4).Value
'MsgBox rec1 & rec2 & rec3 & rec4
Sheets("Sheet2").Select
For j = 2 To lastrow2
If Cells(j, 1).Value = rec1 And Cells(j, 2).Value = rec2 And _
Cells(j, 3).Value = rec3 And _
Cells(j, 4).Value = rec4 Then
Cells(j, 5).Value = Sheets("Sheet1").Range("A" & i).Address
Exit For
End If
If Cells(j, 1).Value = rec1 And Cells(j, 2).Value = rec2 And _
Cells(j, 3).Value = rec3 And _
Cells(j, 4).Value <> rec4 Then
Cells(j, 6).Value = Sheets("Sheet1").Range("A" & i).Address
Cells(j, 9).Value = Sheets("Sheet1").Range("D" & i).Value
Exit For
End If
If Cells(j, 1).Value = rec1 And Cells(j, 2).Value <> rec2 And _
Cells(j, 3).Value = rec3 And _
Cells(j, 4).Value = rec4 Then
Cells(j, 7).Value = Sheets("Sheet1").Range("A" & i).Address
Cells(j, 10).Value = Sheets("Sheet1").Range("B" & i).Value
Exit For
End If
If Cells(j, 1).Value <> rec1 And Cells(j, 2).Value = rec2 And _
Cells(j, 3).Value = rec3 And _
Cells(j, 4).Value = rec4 Then
Cells(j, 8).Value = Sheets("Sheet1").Range("A" & i).Address
Cells(j, 11).Value = Sheets("Sheet1").Range("A" & i).Value
End If
Next j
Next i
End Sub
Currently I am using Excel to compare two datasets like
Sheet Sheet1
Name Date Type Amount
arc 01-01-2010 x 100
b 01-01-2007 y 25
a 01-03-2008 x 124
a 01-03-2010 x 76
and
Sheet Sheet2
Name Date Type Amount
arc ltd 01-01-2010 x 100
b 01-01-2007 y 20
a 01-03-2008 x 124
d 01-05-2007 x 100
a 01-02-2010 x 76
arc 01-01-2010 x 100
and generating an output like below in Sheet2
Name Date Type Amount All All but Value All but date All but name
Original value Original date Original Name
arc ltd 01-01-2010 x 100 $A$2 arc
b 01-01-2007 y 20 $A$3 25
a 01-03-2008 x 124 $A$4
d 01-05-2007 x 100
a 01-02-2010 x 76 $A$5 01-03-2010
arc 01-01-2010 x 100 $A$2
Wtih nerly 20,000 rows Excel takes a large amount of time to process
this. I m told that this can be done very fast with Access. The row
locations can be substituted by record number as track. Please advise
as to how I cn go about doing this in Access.
My VBA code for ready reference:
*************
Sub compare()
'clear columne
Sheets("Sheet2").Range("E2:K65536").ClearContents
'Find the last row to be evaluated for each sheet
Sheets("Sheet1").Select
lastrow1 = Range("A65536").End(xlUp).Row
Sheets("Sheet2").Select
lastrow2 = Range("A65536").End(xlUp).Row
Sheets("Sheet1").Select
For i = 2 To lastrow1
'Transfer each foled for a row into a variable
rec1 = Sheets("Sheet1").Cells(i, 1).Value
rec2 = Sheets("Sheet1").Cells(i, 2).Value
rec3 = Sheets("Sheet1").Cells(i, 3).Value
rec4 = Sheets("Sheet1").Cells(i, 4).Value
'MsgBox rec1 & rec2 & rec3 & rec4
Sheets("Sheet2").Select
For j = 2 To lastrow2
If Cells(j, 1).Value = rec1 And Cells(j, 2).Value = rec2 And _
Cells(j, 3).Value = rec3 And _
Cells(j, 4).Value = rec4 Then
Cells(j, 5).Value = Sheets("Sheet1").Range("A" & i).Address
Exit For
End If
If Cells(j, 1).Value = rec1 And Cells(j, 2).Value = rec2 And _
Cells(j, 3).Value = rec3 And _
Cells(j, 4).Value <> rec4 Then
Cells(j, 6).Value = Sheets("Sheet1").Range("A" & i).Address
Cells(j, 9).Value = Sheets("Sheet1").Range("D" & i).Value
Exit For
End If
If Cells(j, 1).Value = rec1 And Cells(j, 2).Value <> rec2 And _
Cells(j, 3).Value = rec3 And _
Cells(j, 4).Value = rec4 Then
Cells(j, 7).Value = Sheets("Sheet1").Range("A" & i).Address
Cells(j, 10).Value = Sheets("Sheet1").Range("B" & i).Value
Exit For
End If
If Cells(j, 1).Value <> rec1 And Cells(j, 2).Value = rec2 And _
Cells(j, 3).Value = rec3 And _
Cells(j, 4).Value = rec4 Then
Cells(j, 8).Value = Sheets("Sheet1").Range("A" & i).Address
Cells(j, 11).Value = Sheets("Sheet1").Range("A" & i).Value
End If
Next j
Next i
End Sub