Click here to Skip to main content
15,891,763 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to implement below excel formula in vba macro but it's not working,please suggest me right way.
My problem is that I'm trying to find duplicate entry in same column and mark it as duplicate,but it not satisfy the condition.
How to make correct vba condition using this formula?
The formula is
VB
=IF(ISERROR(MATCH(C2,C$2:C$16,0)),"","Duplicate")

and my condition in vb is given below
VB
If WorksheetFunction.IsError(WorksheetFunction.Match(Sheets(1).Cells(cnt, colCnt), Sheets(1).Range("C2:C" & lastRow), 0)) Then

Here,cnt initialize to 2 and lastrow is total rows in current column
Suggest me the right way to do it
Posted
Comments
ZurdoDev 9-Oct-15 8:13am    
I'm not sure what part you are stuck on. Also, you can record a macro doing what you want and you can see the code.

1 solution

If you want to insert formula into C2 cell, try this:
VB
Sheets(1).Range("C2").Formula = "=IF(ISERROR(MATCH(C" & cnt & ",C$2:C$" & lastrow & ",0)),'','Duplicate')"

After that you can read the value (calculated via formula):
VB
retVal = Sheets(1).Range("C2").Value

Note: retval should be declared as string variable
Now, you can use it for further processing:
VB
If retval = "" Then
    'not duplicate 
Else
    'duplicate 
End If
 
Share this answer
 
Comments
Leo Chapiro 9-Oct-15 9:54am    
+5 !
Maciej Los 9-Oct-15 10:38am    
Thank you.
Venkat Raghvan 12-Oct-15 2:46am    
It is giving an error that 'Application-defined or object-defined error'.What is that? How to solve this?
Maciej Los 12-Oct-15 9:47am    
What line?
Venkat Raghvan 15-Oct-15 1:35am    
On formula line

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900