Can I use an Excel macro as a data validation rule?

Posted on 2002-04-19
Last Modified: 2010-05-02
I would like to use a macro function to validate the data entered in a cell, in Excel (like the Data validation).
Question by:octi
  • 3
  • 2
LVL 44

Expert Comment

ID: 6953367
Hi Octi,

What do you want to check for because everything can be done only if you can be a bit more precise it would be easier to build the code


Author Comment

ID: 6953385
I would like to check if the introduced name is in the address book. I have a function to do that.
LVL 44

Accepted Solution

bruintje earned 100 total points
ID: 6953409
and you would trigger this function on a cell change? then something like this could help

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Excel.Range)
  ' call to your function 'NameIsInAddressBook'
  If NameIsInAddressBook(Target.Value) Then
    Msgbox "It's OK"
    ' your code here
    Msgbox "Ÿou entered a new name"    
    ' your code here
  End If
End Sub


Author Comment

ID: 6953426
This event is OK, I tryed with SelectionChange, but the Target was wrong (new selection, instead of old). Thanks.
LVL 44

Expert Comment

ID: 6953438
Great thanks for the A grade

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now