Macro to compare datas

D

Dani Lima

I need to compare a group of lines. On my worksheet there are lines with the
same number or order (colum B) (numericaly classified) and another colum (D)
with same datas, I need to compare if the number of the order are the same
and if the data on the columm d at the same line are the same, if so, the
macre should answer 'yes',if one of the datas on the columm d are different
the macro should answer 'no'.

Someone could help me?

regards, Dani
 
D

Dani Lima

HI! Mike, tks for your help, but I think I wrote someting wrong (english isnt
my first language) and it make you do a macro for another thing.. fortunataly
it will work for another job... but what I really want is:

A B C D
3 31046 31046 Sim
3 31046 Sim
3 31046 não
3 31046 Sim
3 31046 Sim
3 31056 31056 Não
3 31056 Não
3 31056 Não

I need to check if the datas on the column D are equals, according to the
number on the column B. Eg.: for the number 31046 (5 lines) the datas on the
columns D are differents (there are 4 "Sim" and 1 "no"). If all the datas on
this example were "Sim" or "Não" the macro should answer on the column E =
yes and if not (like in this case), should answer "no".

best regards,
"Mike" escreveu:
 
D

dk

try this:

Const COLUMNC As String = "C"
Const COLUMND As String = "D"
Const COLUMNRESULTS = "E"

Dim iStartingRow As Long
Dim iLastRow As Long
Dim blnResult As Boolean

iLastRow = Range(COLUMND & Rows.Count).End(xlUp).Row
blnResult = True
indxNewRow = 2

For iStartingRow = 2 To iLastRow
If Range(COLUMNC & iStartingRow).Value = "" Then
If Range(COLUMND & iStartingRow).Value <> Range(COLUMND & _
iStartingRow - 1).Value Then
blnResult = False
End If
End If
If Range(COLUMNC & iStartingRow).Value <> "" Or iStartingRow =
iLastRow Then
For indxRow = indxNewRow To iStartingRow
If blnResult = False Then
Range(COLUMNRESULTS & indxRow).Value = "NO"
Else
Range(COLUMNRESULTS & indxRow).Value = "YES"
End If
Next
iNewValue = Range(COLUMNC & iStartingRow).Value
indxNewRow = iStartingRow
blnResult = True
End If
Next
 
D

Dani Lima

Thanks, worked perfect!

"dk" escreveu:
try this:

Const COLUMNC As String = "C"
Const COLUMND As String = "D"
Const COLUMNRESULTS = "E"

Dim iStartingRow As Long
Dim iLastRow As Long
Dim blnResult As Boolean

iLastRow = Range(COLUMND & Rows.Count).End(xlUp).Row
blnResult = True
indxNewRow = 2

For iStartingRow = 2 To iLastRow
If Range(COLUMNC & iStartingRow).Value = "" Then
If Range(COLUMND & iStartingRow).Value <> Range(COLUMND & _
iStartingRow - 1).Value Then
blnResult = False
End If
End If
If Range(COLUMNC & iStartingRow).Value <> "" Or iStartingRow =
iLastRow Then
For indxRow = indxNewRow To iStartingRow
If blnResult = False Then
Range(COLUMNRESULTS & indxRow).Value = "NO"
Else
Range(COLUMNRESULTS & indxRow).Value = "YES"
End If
Next
iNewValue = Range(COLUMNC & iStartingRow).Value
indxNewRow = iStartingRow
blnResult = True
End If
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top