1

I have create name range on sheet "A" so I need to use this range as validation ComboBox on sheet B. I want to know how can I setting validation as range using C#?

2
  • You want to know how to this programmatically? if so, what parts of this do you need help with (creating the range; setting the validation as the range, or...). Or you just want to know how to do it manually? Commented Mar 22, 2010 at 8:38
  • I want to know how to setting validation as range using C#. Commented Mar 22, 2010 at 9:28

1 Answer 1

2
+150

The sheets won't matter because you'll just reference the named range of the list value range. Here you go below (assumes Interop) - listValidatingRange is where you have your values that need to be displayed in the dropdown - add that as a named range. cellThatNeedsValidating is the cell that you want the drop-down to appear in - add that as a named range. Then, on cellThatNeedsValidating, add the validation to be that of "=ListValidatingRange".

private void SetValidation()
{

    Microsoft.Office.Tools.Excel.NamedRange listValidatingRange =
        this.Controls.AddNamedRange(this.Range[""C1:C13"", missing],
        "ListValidatingRange");

    Microsoft.Office.Tools.Excel.NamedRange cellThatNeedsValidating =
        this.Controls.AddNamedRange(this.Range[""A1"", missing],
        "cellThatNeedsValidating");

    cellThatNeedsValidating.Validation.Add(
        Excel.XlDVType.xlValidateList ,
        Excel.XlDVAlertStyle.xlValidAlertStop,
        missing, "=ListValidatingRange", missing);
}
Sign up to request clarification or add additional context in comments.

1 Comment

It's work, however I need 4 hours before accept this as correct answer. Furthermore I have another relate question here stackoverflow.com/questions/2497531/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.