Data Validation to only allow a 8 digit HEX value on several cells.

Krulle1000

New Member
Joined
Feb 25, 2016
Messages
15
Hello,

I'm trying to use data validation to validate if the user provides a 8 digit HEX value.

In example data validation in cell K2:
Allow: Custom
Formula: =AND(LEN(K2)= 8;ISNUMBER(HEX2DEC(K2)))

This works but I can't manage to replace the formula with ROW() in order to use it for all my data validation cells.
Formula: =AND(LEN(INDIRECT("K"&ROW()))= 8;ISNUMBER(HEX2DEC(INDIRECT("K"&ROW()))))

Excel returns next error: 'The Formula currently evaluates to an error'

What is wrong here?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I don't think you need the INDIRECT function. If you put your original formula in row 2 and drag-copy down, the formula will automatically adjust the relative references in the formulas for each row.
 
Last edited:
Upvote 0
Thanks AlphaFrog
Indeed, the drag-copy down adjusts the formula with the relative references.
Now, if I would like to apply the data validation to several ranges (with slightly different formulas) by using vba code.
I assume that this could be done by using the Range.AutoFill method?
 
Upvote 0
You could use VBA autofill. Alternativelly, if you apply the data validation to the entire range, the relative references will adjust.

Code:
    [color=darkblue]With[/color] Range("[B]J2:J100[/B]").Validation
        .Delete
        .Add Type:=xlValidateCustom, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="=AND(LEN(K2)= 8;ISNUMBER(HEX2DEC(K2)))"
        .IgnoreBlank = [color=darkblue]True[/color]
        .InCellDropdown = [color=darkblue]True[/color]
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = [color=darkblue]True[/color]
        .ShowError = [color=darkblue]True[/color]
    [color=darkblue]End[/color] [color=darkblue]With[/color]
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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