Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 747
Default Search and Disallow macro in Excel

My read was that you wanted to have it deny duplicate entries 'as they are
typed' similar to the Data Validation feature except that the latter allows
you to specify only what is allowed as opposed to what is denied.

Paste the following to the worksheet code module:-
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng1 As Range, rng2 As Range
Dim ws2 As Worksheet
Dim c As Range
Dim Msg As String, Title As String

Set ws2 = Sheets("Sheet2")
Set rng1 = Me.Columns(1)
Set rng2 = ws2.Range(ws2.Range("A1"), _
ws2.Range("A1").End(xlDown))
If Target.Count 1 Then Exit Sub
Title = "Data Validation"
If Not Intersect(Target, rng1) Is Nothing Then
Set c = rng2.Find(Target.Value, , , xlWhole)
If Not c Is Nothing Then
With Target
..Select
Msg = "Entry denied !!!" & vbCr & vbCr & _
"The word """ & .Value & _
""" already exists on " & rng2.Parent.Name & ". "
MsgBox Msg, vbCritical, Title
..ClearContents
End With
End If
End If
Set rng1 = Nothing
Set rng2 = Nothing
Set c = Nothing
End Sub

Regards,
Greg


"ChristalClarity" wrote:

I want to structure a macro that will automatically search entries in a
colunm on worksheet A, compare those entries to a column in spreadsheet B and
then disallow the entry if there is a match.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro to disallow shading in certain columns Tami Excel Worksheet Functions 2 December 18th 09 04:21 PM
In Excel, how can I tell the program to disallow duplicate data i. gthawkster Excel Worksheet Functions 5 December 15th 04 04:42 AM
Excel XP VBA code to search all macro code in Excel module for specific search string criteria Ed[_18_] Excel Programming 4 May 20th 04 02:08 PM
Excel XP VBA code to search all macro code in Excel module for specific search string criteria Frank Kabel Excel Programming 0 May 19th 04 08:11 PM


All times are GMT +1. The time now is 11:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"