0
votes

Referencing: Google Apps Script for Multiple Find and Replace in Google Sheets

I'd like to use this same code for my purposes but only within 1 column... Any advice on how to limit this script to only one column? The reason is that when I run this to change Department Names in Column J, it works perfectly, except it also changes the 'Data Type' in my Date (Columns L and M) to include timezones, and that messes up other Sheets referencing those dates... Thanks!

1
Welcome. The key to your problem is var values = sheet.getDataRange().getValues();. getDataRange() pulls data from ALL the columns. You need something like var values = sheet.getRange(1,10,rows).getValues(); to limit the data to just Column J (column 10). Use/adapt the "trick" described here by Mogsdad to get the last row for column J, which will give you the "rows" value. Then when you've finished, you use something like sheet.getRange(1,10,rows).setValues(values);Tedinoz
Thanks @Tedinoz! I took your advice and messed around, tripping & stumbling along the way. I ended up switching out function replaceInSheet(sheet, to_replace, replace_with) { //get the current data range values as an array var values = **sheet.getDataRange()**.getValues(); with function replaceInSheet(sheet, to_replace, replace_with) { //get the current data range values as an array var values = **sheet.getRange('J:J')**.getValues();Corey Pomkoski

1 Answers

0
votes

I ended up switching out

function replaceInSheet(sheet, to_replace, replace_with) {
//get the current data range values as an array 
var values = sheet.getDataRange().getValues();

with

function replaceInSheet(sheet, to_replace, replace_with) {
//get the current data range values as an array 
var values = sheet.getRange('J:J').getValues();