Sorting fails to move data validation rules along with data in Excel

You can make a general rule for handling pH values and apply it to the whole column of values. You just have to include a condition that checks Key1 to see if the value is a pH; if it is, check the criteria; if not, just return TRUE so anything is allowed.

For example, here is a custom data validation rule applied to C2:C6 (Value 1 column) in your table:

=IF(B2="pH",AND(C2>=0,C2<=14,C2=INT(C2)),TRUE)

This will limit pH values 0<=pH<=14 and only whole numbers. Since the rule is applied to the whole column, sorting will not affect the data validation.

enter image description here

You can handle borders in a similar way if you apply them using conditional formatting. Just apply it to all the data in the column with an appropriate formula rule, such as

=B2="pH"

enter image description here