in Google sheets this is very easy trick to find data like lots of number or name we do Copy and use Ctrl+F find and we do Ctrl-V so in google sheets we can easly find same data like I like google sheets script that when we do Ctrl+C then auto hilight that same data is avalbale in google sheets Test File
Thank you so much for your time
in Google sheets this is very easy trick to find data like lots of number or name we do Copy and use Ctrl+F find and we do Ctrl-V so in google sheets we can easly find same data like I like google sheets script that when we do Ctrl+C then auto hilight that same data is avalbale in google sheets Test File
Thank you so much for your time
Share Improve this question asked Mar 12 at 7:11 Sanjay DevaniSanjay Devani 317 bronze badges 4 |2 Answers
Reset to default 1Highlighted same value on selected cell
Instead of using Crtl + C
you may also try this solution using onSelectionChange trigger to automatically highlight the matching value when you select a cell.
For highlighted cells #FFFF00 (yellow)
for (let i = 0; i < values.length; i++) {
for (let j = 0; j < values[i].length; j++) {
backgroundColors[i][j] = values[i][j] == selectedValue ? "#FFFF00" : "#FFFFFF";
}
}
Reset all cells to white if a blank cell is selected
for (let i = 0; i < values.length; i++) {
for (let j = 0; j < values[i].length; j++) {
backgroundColors[i][j] = "#FFFFFF";
}
}
Script used :
function onSelectionChange(e) {
const sheet = e.range.getSheet();
const selectedValue = e.range.getValue();
const range = sheet.getDataRange();
const values = range.getValues();
const backgroundColors = range.getBackgrounds();
if (selectedValue === "") {
for (let i = 0; i < values.length; i++) {
for (let j = 0; j < values[i].length; j++) {
backgroundColors[i][j] = "#FFFFFF";
}
}
} else {
for (let i = 0; i < values.length; i++) {
for (let j = 0; j < values[i].length; j++) {
backgroundColors[i][j] = values[i][j] == selectedValue ? "#FFFF00" : "#FFFFFF";
}
}
}
range.setBackgrounds(backgroundColors);
}
Set Up the Trigger :
Click the clock icon (Triggers).
Add a new trigger.
Choose onSelectionChange.
Set event type to On Edit.
Click Save.
Sample Output
Note: I uploaded this GIF to show a sample result.
You want to enter, or copy/paste, a value into a cell, and have all cells containing that value to be highlighted.
Consider the following script:
- it is triggered by an installable
onEdit
trigger. Op must do this. - The OP enters (or copy/paste) a value into cell J2
function searchNumber(e) {
// Logger.log(JSON.stringify(e)) // DEBUG
const sheetName = "Sheet3"; // This is from your provided Spreadsheet.
const targetRow = 2
const targetCol = 10
const targetColor = "#FFFF00"
const { range } = e;
const sheet = range.getSheet();
if (sheet.getSheetName() == sheetName && range.rowStart == targetRow && range.columnStart == targetCol){
// valid edit
Logger.log("edit on the correct sheet and cell")
// get the data range
var dataRange = sheet.getRange(1,1,sheet.getLastRow(),sheet.getLastColumn())
// Logger.log("DEBUG: the data range = "+dataRange.getA1Notation())
// reset the sheet background colours
dataRange.setBackground("#FFFFFF")
// Logger.log("DEBUG: reset the background colours")
// get the values
const dataValues = dataRange.getValues();
// Logger.log("values = "+dataValues) // DEBUG
// Logger.log("data values rows = "+dataValues.length+", data values columns = "+dataValues[0].length) // DEBUG
// get the edited value
const editedValue = range.getValue()
// Logger.log("DEBUG: editedValue = "+editedValue)
// loop through the sheet looking for a value matching the edited value
for (let i = 0; i < dataValues.length; i++) {
for (let j = 0; j < dataValues[0].length; j++) {
if (dataValues[i][j] == editedValue ){
// Logger.log("DEBUG: i:"+i+", j:"+j+", data value= "+dataValues[i][j])
sheet.getRange(i+1,j+1).setBackground(targetColor)
}
}
}
}
else{
// not a valid edit
Logger.log("edit in an invalid cell")
}
// Logger.log("DEBUG: done")
}
SAMPLE output
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744767060a4592525.html
CTRL+C
key. But it might still be possible to capture other key shortcuts(likeCtrl+alt+shift+1
) using macro developers.google/apps-script/guides/sheets/macros – TheMaster Commented Mar 12 at 8:56