exclude range from range

ktab

Well-known Member
Joined
Apr 21, 2005
Messages
1,297
Hello,

At the following code how may i exclude the activecell's range from range?
columns(1).find(activecell.value,lookat:xlwhole)

I want each time an entry is made to look for dubs (at worksheet change event), so i do not want to look for activecell's value too.

Thank you
Kostas
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
Hi Kostas

Assuming the active cell in in column A

I don't think you need to exclude the active cell from the range, you can use the parameter After and force the Find to start after the active cell. This way you just have to check the address returned. If it's the address of the active cell it means it's the only cell in the range with that value.
Code:
If Columns(1).Find(ActiveCell.Value, after:=ActiveCell, lookat:=xlWhole).Address _ 
                            = ActiveCell.Address Then
   ' not duplicate
Else
   ' duplicate
End If
Anyway can you not just use data validation?

Hope this helps
PGC

EDIT: replaced can by need to
 

ktab

Well-known Member
Joined
Apr 21, 2005
Messages
1,297
It's working like:
Code:
Set w = Range("a:a").Find(activecell.offset(-1,0).Value, lookat:=xlWhole)
If Not w Is Nothing And Not w.Address = ActiveCell.Offset(-1, 0).Address Then
    If MsgBox("Code already exist. Dublicate entry?", vbQuestion + vbYesNo + vbDefaultButton2, "Dublicated entry found") = vbNo Then activecell.offset(-1,0).Value = "": ActiveCell.Offset(-1, 0).Activate: Exit Sub
End If
 

Forum statistics

Threads
1,136,654
Messages
5,677,012
Members
419,668
Latest member
DharmaK

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top