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

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
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,214,980
Messages
6,122,563
Members
449,088
Latest member
Motoracer88

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