# Add a Value for first value in Column

I need a macro that would assign a 1 to the first value and a 0 to each additional value that is the same. IE

Apple  1
Apple  0
Apple  0
Orange 1
Banana 1
kiwi 1
Banana 0

Searching Column E and Put the value in Column N start at row 2.

Thanks,
Montrof
LVL 1
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Finance AnalystCommented:
No need for VBA

=IF(COUNTIF(\$E\$2:\$E2,\$E2)=0,1,0)

Copied down as far as required.

Thanks
Rob H
0
Excel & VBA ExpertCommented:
@Rob

If I am not wrong, tt should be like this.....

``````=IF(COUNTIF(\$E\$2:\$E2,\$E2)=1,1,0)
``````
0
Excel & VBA ExpertCommented:
If you really need a VBA solution, you may try this.....
``````Sub Put1ForUniqueItems()
Dim lr As Long
Dim Rng As Range, Cell As Range, chkRng As Range

lr = Cells(Rows.Count, "E").End(xlUp).Row
Set Rng = Range("E2:E" & lr)

For Each Cell In Rng
Set chkRng = Range(Cells(2, "E"), Cells(Cell.Row, "E"))
If WorksheetFunction.CountIf(chkRng, Cell) = 1 Then
Cells(Cell.Row, "N") = 1
Else
Cells(Cell.Row, "N") = 0
End If
Next Cell
End Sub
``````
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
This is perfect Thank you so much!!
0
Excel & VBA ExpertCommented:
0
Finance AnalystCommented:
Sktneer - correct, I omitted to offset by a row to count the cells above.
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.