Compare Cell Values

JonRowland

Active Member
Joined
May 9, 2003
Messages
376
Office Version
365
Platform
Windows
Hi,

I'm running a loop to run through a series of rows in order to identify duplicate rows and then delete then.

So what the code will look for is a time within 2 seconds contained within row B.

If this is true then to check values in C & D are same. However values in C&D will only be unique for the last 10 digits so I thought the RIGHT function would be good to use but when running this bit of code I get a run-time error 424 "OBJECT REQUIRED"

<code>

Row = 2
LastRow = Cells.Find("*", Cells(1), xlFormulas, xlWhole, xlByRows, xlPrevious).Row
Do
Deleted = False
TIME1 = Cells(Row, 2)
TIME2 = Cells(Row + 1, 2)
DIFFERENCE12C = DateDiff("s", TIME1, TIME2)

Cells(Row, 1).Select

If DIFFERENCE12C <= 2 And DIFFERENCE12C >= -2 Then

cct1 = Right(Cells(Row, 3 + columnoffset), 10).Value
cct2 = Right(Cells(Row, 3 + columnoffset), 10).Value
rct1 = Right(Cells(Row, 4 + columnoffset), 10).Value
rct2 = Right(Cells(Row + 1, 4 + columnoffset), 10).Value
ez1 = Cells(Row + 1, 11)

If cct1 = cct2 And rct1 = rct2 Then
If ez1 > 0.5 Then
Cells(Row, 6).Value = "ez1"
End If
Rows(Row + 1).Delete
Deleted = True
Else
End If
End If

If Deleted = False Then Row = Row + 1
If Deleted = True Then LastRow = LastRow - 1

Loop Until Row > LastRow
</code>

I've read that I may need to use a SET statement but not sure what I need to do so any help would be welcome.
Thx
Jon
 

Some videos you may like

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,770
The Right function returns a string. Strings do not have .Value properties.

Perhaps
Code:
Row = 2
LastRow = Cells.Find("*", Cells(1), xlFormulas, xlWhole, xlByRows, xlPrevious).Row

For Row = LastRow To 2 Step -1
    
    TIME1 = Cells(Row, 2)
    TIME2 = Cells(Row + 1, 2)
    
    DIFFERENCE12C = DateDiff("s", TIME1, TIME2)
    
    If Abs(DIFFERENCE12C) <= 2 Then
    
        cct1 = Right(CStr(Cells(Row, 3 + columnOffset).Value), 10)
        cct2 = Right(CStr(Cells(Row + 1, 3 + columnOffset).Value), 10)
        rct1 = Right(CStr(Cells(Row, 4 + columnOffset).Value), 10)
        rct2 = Right(CStr(Cells(Row + 1, 4 + columnOffset).Value), 10)
        ez1 = CStr(Cells(Row + 1, 11).Value)
    
        If cct1 = cct2 And rct1 = rct2 Then
            If ez1 > 0.5 Then
                Cells(Row, 6).Value = "ez1"
            End If
            Rows(Row + 1).Delete
        End If
    End If
Next Row
 

JonRowland

Active Member
Joined
May 9, 2003
Messages
376
Office Version
365
Platform
Windows
mikerickson,

Something new to add to my developement VBA knowledge. Works perfectly.

Thx
Jon
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,977
Messages
5,514,585
Members
409,006
Latest member
Parson9

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top