How to use named range in validation list?

Mar 24, 2011 at 9:57 AM

Good day,


I would like to know how to use a named range in a validation list? I can create the named range easily but I have no idea how to link up the named range to a validation.





Mar 24, 2011 at 12:43 PM

Ok, I have found the answer on one site.  Here is a sample if anyone wants to know:

           Use a Workbook variable called: SummarySheet


  NPOI.HSSF.UserModel.HSSFName newNamedRange = Wb.CreateName();
            newNamedRange.NameName = "Priority";
            newNamedRange.Reference = "Summary!$X$2:$X$4";

            //add the data validation to the first column (1-100 rows)
            NPOI.HSSF.Util.CellRangeAddressList rangeList = new NPOI.HSSF.Util.CellRangeAddressList();
            rangeList.AddCellRangeAddress(new NPOI.HSSF.Util.CellRangeAddress(0, 100, 6,6);

            DVConstraint dvConstraint = DVConstraint.CreateFormulaListConstraint("Priority");

            //add the data validation to sheet

            NPOI.HSSF.Util.HSSFDataValidation dataValidation = new
         NPOI.HSSF.Util.HSSFDataValidation(rangeList, dvConstraint);