Assuming you have interop, it would be like the below. Note xlValidateWholeNumber
, that can be changed to xlValidateDecimal
(and the subsequent Formula1 below would need to be a decimal) for decimals).
private void SetValidationBetweenNumbers()
{
Microsoft.Office.Tools.Excel.NamedRange cellThatNeedsValidating =
this.Controls.AddNamedRange(this.Range[""A1"", missing],
"cellThatNeedsValidating");
cellThatNeedsValidating.Validation.Add(
Excel.XlDVType.xlValidateWholeNumber,
Excel.XlDVAlertStyle.xlValidAlertStop,
Excel.XlFormatConditionOperator.xlBetween, "1", "=B1");
}