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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

776 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