5
When sorting a table or range in Excel, the cell values and basic formatting like bold, italic, colours etc. move, but the following things do NOT move:
- Borders
- Data validation rules
My spreadsheet has per-cell data validation, so when I perform a sorting operation it moves values around but doesn't carry their validation with them.
Here's an example before sorting:
And after sorting (A-Z on "Fruit" name.)
Is there a way to make Excel move the data validation rules along with with the values and formats when Excel performs a sorting operation?
Edit:
Just to clarify, I have two separable concerns here:
- Primary concern: If a user decides to click the Sort button, or the Sort option on a Filter column heading, this will trash my (complex!) data validation rules.
- Secondary concern: It would be nice if my worksheet could be sorted using the inbuilt Excel buttons for sorting (these are the most obvious ways to sort data). A separate macro just for doing a sort seems a bit hacky.
Edit:
My eventual solution was just to disable sorting entirely, by protecting the workbook and disabling sorting for all sheets. You can press the "Sort" buttons but they do nothing.
As an additional safeguard, I added VBA that re-applies Protect Workbook every time the workbook is opened, and brings up a worksheet with usage instructions and warnings (such as "Don't sort this!".) The end-user can un-protect the workbook at any time, so this isn't foolproof, but I believe it's the best I can do.
Do you know how to use VBA? you can do borders by recording a macro. I'll look up what I have for moving validators. AFAIR its in VSTO c#. – Jeremy Thompson – 2012-08-14T05:48:58.270
@JeremyThompson: My VBA skills are modest - I'm actually learning VBA as I go for this particular job. Borders don't bother me, it's the data validation that's important. I don't want it accidentally munged if someone clicks the "Sort" button. – Li-aung Yip – 2012-08-14T06:12:19.263