Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We are creating a data validation list from C# code. This list will contain Month with year. How can we restrict excel from converting this list from changing to date format?

Below is the code: 


C#
range.Validation.Add(XlDVType.xlValidateList,
                               XlDVAlertStyle.xlValidAlertInformation,
                               XlFormatConditionOperator.xlBetween,
                               flatList,
                               Type.Missing);
range.Validation.IgnoreBlank = false;
range.Validation.InCellDropdown = true;


flatList will have values "June 2016, July 2016, August 2016". Excel converts the list to "Jun-2016, Jul-2016, Aug-2016". We want that to be avoided and the list should remain as text. 

Please advice.


What I have tried:

Tried making the cell format as text but no luck.
Posted

1 solution

Try putting an apostrophe (single quote) ' at the beginning of the entries in flatList...

'June 2016, 'July 2016, 'August 2016, etc.

or, if you're using a named range where each one is in a separate cell:

'June 2016
'July 2016
'August 2016
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900