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

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,516
Messages
6,119,979
Members
448,934
Latest member
audette89

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
Back
Top