Data Validation - Custom function VBA

webdevptg

Board Regular
Joined
May 2, 2019
Messages
51
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
  2. Web
PS: translate by Google translate ?

Hi,

have a function VBA that verifies the Portuguese TIN is valid (Como validar um NIF no Excel - www.JJoao.com) through the control digit and intended to use this function in the validation of data, in order to inform the user if the number was not valid, since the function returns a boolean value.

For example in cell A1, I create a custom data validation and place = verificaNIF (A1), but I get an error stating:


Cannot find a range with the name you specified


There is no problem in userform or Vba, but this cell validation must be included in cells.

1539528.png

What am I doing incorrect?


Thanks
 

Attachments

  • 1539528.png
    1539528.png
    121 KB · Views: 172

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Data validation's formula cannot be a user-defined function directly. You can, however, have it look at a cell that utilises the UD function. (And that could be in a hidden Worksheet if you don't want it to be obvious.)

So, to illustrate, this works (where the function YN returns a TRUE/FALSE for even/odd values):

1579668732755.png
where B1 has a data validation formula of
1579668763246.png


In my example above, my YN function is
VBA Code:
Function YN(x As Integer) As Boolean
    If x Mod 2 = 0 Then YN = True
End Function

So if 1,3,5,... is entered into B1:
1579668891703.png
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,800
Members
449,468
Latest member
AGreen17

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