1

I'm trying to clear all the values from a Google Sheets sheet, while keeping the formatting and data validation (e.g. dropdowns and checkboxes). The documentation for the spreadsheets.values.clear API method says,

Only values are cleared -- all other properties of the cell (such as formatting, data validation, etc..) are kept.

However, when I run this method, the data validations I have set up on the sheet are deleted.

I suppose I'm both trying to report a bug (the support website directs me to StackOverflow), and also soliciting any suggestions for how I might accomplish the "clear all values but leave formatting and data validation" task.

1
  • Same here unfortunately. It seems the docs are just incorrect. It clears everything. Commented Jun 27 at 11:18

1 Answer 1

0

I just tried it myself on bound script against a basic sheet with data in a few columns and rows and it worked fine. It cleared only the data and left the formatting and data validation. The function was as follows :

function myFunction() {
  let sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
  let range = sheet.getRange(1,1,sheet.getLastRow(),sheet.getLastColumn());
  range.clear();
}

Are you running this bound, or unbound? How are you selecting the range?

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

2 Comments

Hi Dan, thanks for this suggestion. I'm not running this using Google Apps Script - I'm using the Sheets v4 API, which has different behavior
Whoops. Sorry I missed that. Does the behavior change whether you use A1 or R1C1 notation when specifying the range? Or is the result the same in either case?

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.