- Input a search value.
- You want to run Google Apps Script by the menu bar.
- Search the column "A" for each sheet using the search value, and when the searched value is found at the column "A", it retrieves the row.
- There are sheets you don't want to use for searching.
You want to show the result as follows.
Creative "C6" was found in "Second", "fifth" tab
Second Tab: Impression:100 / Click:100
Fifth Tab: Impression:100 / Click:100
I understood like above. If my understanding is correct, how about this sample script? Please think of this as just one of them.
Flow:
- When Spreadsheet is opened, the custom menu is added.
- Run the script from "Show prompt" of the custom menu. By this, a dialog box is opened.
- Input a search text to the text input field, and click "ok" button.
- At the script, the rows are searched with TextFinder using the inputted search text.
- Show the result by a dialog box as a sample.
Sample script:
Before you run the script, please set the sheet name to sheets
.
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('Custom Menu')
.addItem('Show prompt', 'showPrompt')
.addToUi();
}
function showPrompt() {
// Please set the sheet name you want to use for searching.
var sheets = ["first", "second", "third", "fourth", "fifth", "sixth"];
var ui = SpreadsheetApp.getUi();
var res = ui.prompt('Sample', 'Input search text:', ui.ButtonSet.OK_CANCEL);
var button = res.getSelectedButton();
if (button == ui.Button.OK) {
var findText = res.getResponseText();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var header = "Creative \"" + findText + "\" was found in ";
var values = "";
var object = sheets.reduce(function(obj, sheetName, i) {
var sheet = ss.getSheetByName(sheetName);
var textFinder = sheet.createTextFinder(findText);
var searchedRows = textFinder.findAll().reduce(function(ar, e) {
if (e.getColumn() == 1) {
var row = sheet.getRange(e.getRow(), 1, 1, sheet.getLastColumn()).getValues()[0];
if (row[0] === findText) {
ar.push(row);
header += '"' + sheetName + '"' + (i == sheets.length - 1 ? " tab\n" : ", ");
values += sheetName + " Tab: Impression:" + row[1] + " / Click:" + row[2] + "\n";
}
}
return ar;
}, []);
if (searchedRows.length > 0) obj[sheetName] = searchedRows;
return obj;
}, {});
Logger.log(object);
ui.alert(header + values);
}
}
![enter image description here](https://i.stack.imgur.com/GrNih.png)
![enter image description here](https://i.stack.imgur.com/4hvOU.png)
Note:
- This is a sample script. please modify this for your situation.
References:
Edit:
- When the searched text was not found, you want to show "The creative you just searched for does not exist, please go back and check if there is any typo!".
In order to reflect your above request to the script, please modify above script as follows.
From:
ui.alert(header + values);
To:
if (Object.keys(object).length > 0) {
ui.alert(header.slice(0, -2) + " tab\n" + values);
} else {
ui.alert("The creative you just searched for does not exist, please go back and check if there is any typo!");
}
Creative
) using a value. Is my understanding correct? 2. What is the tool bar you think? 3. In your tag, "Javascript" is used. Do you want to achieve this using Javascript which is not Google Apps Script? 4. Can you provide your current script? 5. What is the tab of "RAW"? In your actual Spreadsheet, is the tab you don't want to search included? I apologize for my poor English skill. – Tanaiket include it here) And yes, that is the tab I don
t want to be searched since that is just raw data. 4) For the script, frankly speaking, I haven`t written specifically for this tool-bar task, but i have the API call, raw data transformation and split into the separate tab code.. Should we look into this code as well? I really have no clue how I should start for creating this tool-bar... – StarSpirit_2000