スクリプトが機能しないのはなぜですか? データを検索しません。メッセージは完了を示していますが、シートは変更されていないように見えます。誰を助けることができますか?
function SearchReplaceInFormula() { //begin work
var pattern = Browser.inputBox("Enter the search string:"); //text on label
var replacement = Browser.inputBox("Enter the replacement string:"); //text on label
if (pattern == "" && replacement == "") // empty
{
Browser.msgBox("Nothing to search and or replace");
return;
}
//
var formula = SpreadsheetApp.getActiveRange().getValues(); //get a data all range
var range = SpreadsheetApp.getActiveRange(); //get range
var crows = range.getNumRows(); //last rows
var ccols = range.getNumColumns(); //last columns
var row = 0; //
for (row = 1; row <= crows; row++)//
{
for (col=1; col <= ccols; col++) //
{
var cell = range.getCell(row, col);
var formula = cell.getValues(); //may be getValue
var updated = formula; //update
while(-1 != updated.indexOf(pattern)) //what -1
{
updated = updated.replace(pattern, replacement); //replace before update
}
if (formula != updated)
{
cell.setFormula(updated) //set vales?
}
}
}
Browser.msgBox("Done replacing " + pattern + " with " + replacement); //shows always
}