13

I want to remove all data validations from a sheet, tried following but it does not get rid of them. Anyway to do this through apps script?

var ss = SpreadsheetApp.getActiveSpreadsheet();
var accountSheet = ss.getSheetByName("Account A");
accountSheet.getRange(1,1,274,61).clear();
3
  • 2
    Looks like it is a known bug with clear() although one can alternatively use clearDataValidations() which works. Commented Feb 9, 2016 at 17:27
  • I get: TypeError: Cannot find function clearDataValidations in object C2:D7. Commented Sep 18, 2016 at 8:11
  • Ah I see, need to do something like: var validations_to_clear = active_sheet.getRange(2, 3, 6, 2); Commented Sep 18, 2016 at 8:25

2 Answers 2

28
accountSheet.getRange(1,1,274,61).setDataValidation(null)

That should do the job.

Sign up to request clarification or add additional context in comments.

Comments

0

A more generic answer to remove all data validations from the whole sheet (remove from all cells in sheet):

mySheet.getRange(1,1, mySheet.getMaxRows(), mySheet.getMaxColumns()).setDataValidation(null);

You could in theory use this less verbose version (might be faster because it affects a smaller range of cells):

mySheet.getDataRange().setDataValidation(null);

However, there may be empty cells outside the DataRange that do have validations and those validations will not be removed (they are outside the scope of DataRange, won't be selected by DataRange). Hence, you should use the first version I mentioned for more robust code: it selects all the cells in the sheet and removes validations.

Comments

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.