[VBA Excel 2003] How to do it in VBA?

A

Anitacr

I need to verify in a column which cells are duplicated.
I don´t know how to do it in VBA, or the correct Excel´s function.
Example:

Column X

9675
9868
9868
9619
9868
9619
9619
9619
9619
9619

I want to identify the cells with same contents and mark them, with a
conditional format.

Anybody can help me?

Please!
 
B

Barb Reinhardt

I think I'd do it something like this (completely untested)

Dim myRange as Range
Dim r as range
Dim lRow as long

Dim aWS as worksheet
Set aWS = activesheet

set myRange = aws.cells(1,1) 'Change to first cell in range to test
lRow = aws.cells(aws.rows.count,myrange.column).end(xlup).row

Set myRange = myrange.resize(lrow-myrange.row + 1,1)

for each r in myrange
if not isempty(r) then
if application.worksheetfunction.countif(myrange,r.value) > 1 then
'Apply conditional format
end if
end if
next r
 
R

Ron Rosenfeld

I need to verify in a column which cells are duplicated.
I don´t know how to do it in VBA, or the correct Excel´s function.
Example:

Column X

9675
9868
9868
9619
9868
9619
9619
9619
9619
9619

I want to identify the cells with same contents and mark them, with a
conditional format.

Anybody can help me?

Please!

Just use application.worksheetfunction.countif(range,cell) > 1 to determine if
the cells are duplicated.
--ron
 
T

The Code Cage Team

Don't use a macro its overkill for something simple, you can use conditional
formatting you can select the whole area to give it a name like range1 select
conditional formatting>formula is, paste this in =COUNTIF(range1,A1)>1 and
select your colour, now all duplicates will e highlighted!

Regards,
The Code Cage Team
www.thecodecage.com/forumz
 

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

Similar Threads

Excel VBA 1
Validate Cell Value 11
Conditional formatting with vba 3
Find all in vba 5
Excel VBA help: Text file formatting 19
If Then or Case help 3
Apply cell formatting using VBA 1
VBA to Identify changes in row1 3

Top