Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2002-04-19
5
Medium Priority
?
180 Views
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).
Thanks,
Octi
0
Comment
Question by:octi
  • 3
  • 2
5 Comments
 
LVL 44

Expert Comment

by:bruintje
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

:O)Bruintje
0
 

Author Comment

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

Accepted Solution

by:
bruintje earned 400 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
  Else
    Msgbox "Ÿou entered a new name"    
    ' your code here
  End If
 
End Sub

:O)Bruintje
0
 

Author Comment

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

Expert Comment

by:bruintje
ID: 6953438
Great thanks for the A grade
0

Featured Post

Hire Technology Freelancers with Gigs

Work with 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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

963 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