PDA

View Full Version : Basic question on cell comparison



yoelgr
03-17-2011, 11:19 AM
I am new to VBA, so this is probably a very dum question. I am trying to compare cells in one column to those in another. I.e. I choose a cell in one column, and I want to check if its content exists in the second column. Cells contain strings. I am writing:
For i = 0 To composerCount
If Cells(r, 9).Value = Cells(i, 20).Value Then
isNew = False
End If
I have also tried without the .Value, but neither work. What is the correct syntax?

xld
03-17-2011, 11:27 AM
That is how it is done, so what is the problem?

Maybe you just want t check if it exists in any row?



For i = 0 To composerCount

isNew = IsError(Application.Match(Cells(r, 9).Value, Columns(20),0))
Next i

yoelgr
03-17-2011, 11:33 AM
That is how it is done, so what is the problem?

Maybe you just want t check if it exists in any row?



For i = 0 To composerCount

isNew = IsError(Application.Match(Cells(r, 9).Value, Columns(20),0))
Next i


Thanks for the reply. When I use the code I wrote, I get:
I get Run-time Error '1004': Application-defined or object-defined error.

mdmackillop
03-17-2011, 01:44 PM
Can you post the whole of your code so we can see how IsNew is implemented.

xld
03-18-2011, 03:16 AM
Thanks for the reply. When I use the code I wrote, I get:
I get Run-time Error '1004': Application-defined or object-defined error.

I doubt that error is in that code.

As MD suggested, post the workbook or all the code for us to see.