Add hyperlinks to data validation list (drop-down menu) - google-sheets

Google Sheets:
I have data validation list in cell A1.The drop down menu has values a,b,c.
I want links to each of them to a specific cell, like user selects "a" from the drop-down and it goes to cell a5, b goes to cell c44 and so on...
What I need:
**Scripts that can very fast.
Please please help.

It could be something like this:
function onEdit(e) {
var ss = e.source;
var name = ss.getActiveSheet().getName();
if (name != 'Sheet1') return;
var col = e.range.columnStart;
var row = e.range.rowStart;
if (col != 1 && row != 1) return;
var sheet = ss.getSheetByName('Sheet1');
var value = e.value;
switch (value) {
case ('Place 1'): sheet.getRange('c1').activate(); break;
case ('Place 2'): sheet.getRange('c2').activate(); break;
case ('Place 3'): sheet.getRange('c3').activate(); break;
}
}
Here is the sheet

Make a table with choices and cells
try with
=iferror(hyperlink("#gid=12345678range="&vlookup(A1,table,2,0), "link to "&vlookup(A1,table,2,0)))
where 12345678 is the gid of the sheet and table the list of choices/cells
You will have to click twice but it will go faster to the cell

Related

Google Sheets - Copy & Paste Specific Cells from one sheet to first empty row in another sheet if condition is met, then delete the row

first time posting and new at all of this, so I apologize in advance.
I have 2 sheets, "Origin" sheet and "Destination" sheet.
In the Origin sheet, if "APPROVED" is typed and entered in column C, then I would like:
the text in the cells from column A of that row to go to the first blank row of column C in Destination sheet AND
-for the text in the cells from column B of that row to go to the first blank row of column B in Destination sheet.
I have only been able to find the code below that works to copy the entire row. I would like to retain all of the function of deleting the row in the Origin sheet once it is copied.
Thanks in advance!
[Code
function onEdit(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Origin'); //source sheet
var testrange = sheet.getRange('C:C');
var testvalue = (testrange.getValues());
var csh = ss.getSheetByName('Destination'); //destination sheet
var data = [];
var j =[];
//Condition check in G:G; If true copy the same row to data array
for (i=0; i<testvalue.length;i++) {
if ( testvalue[i] == 'APPROVED') {
data.push.apply(data,sheet.getRange(i+1,1,1,11).getValues());
//Copy matched ROW numbers to j
j.push(i);
}
}
//Copy data array to destination sheet
csh.getRange(csh.getLastRow()+1,1,data.length,data[0].length).setValues(data);
//Delete matched rows in source sheet
for (i=0;i<j.length;i++){
var k = j[i]+1;
sheet.deleteRow(k);
//Alter j to account for deleted rows
if (!(i == j.length-1)) {
j[i+1] = j[i+1]-i-1;
}
}
}

Problem with recording data change in google sheet

I have two sheets. On one sheet (Sheet1), I have a column 'A' which has 5 fixed values, and a column 'B' which records the timestamp value in 'A' change. The other sheet (Sheet2) is meant to record all the changes in the first sheet in one day.
I use this simple query in the recording sheet:
=QUERY(Sheet1!A$1:X,"select * where C>="& Sheet2!D1)
with Sheet1!C has timestamps and Sheet2!D1 is the timestamp of 12:00 AM today
The problem is when I change the value of a row in C columns more than one time, instead of creating a new row in Sheet2 it change the value of that row in Sheet2 into new values.
So how do I change my code to get my desire results?
EDIT 2: here is my new code, but it doesn't help.
function importdata(x) {
// var row = x.range.getRow();
// var col = x.range.getColumn();
var addedsheet=SpreadsheetApp.getActive().getSheetByName("Change"); // Sheet where I want to keep the record of the change
var original_sheet = SpreadsheetApp.getActive().getSheetByName("Master"); //sheet where the change is happended
var compared_value = addedsheet.getRange(1,4).getValue(); // Cell D1 of sheet "Change", which has timestamp of today
var insert_area = original_sheet.getRange("A2:X").getValues() // area to get value from "Master" sheet to put into "Change"
var compared_area = original_sheet.getRange("C2:C").getValues(); // area where has timestamp
if (compared_area >= compared_value){
addedsheet.values.append([insert_area])}
} //if timestamp of one row from Master is greater than the value at Change!D1 =>append that row at the end (this is what I'm trying to do)
EDIT 3: I fixed the above code by append[insert_area][0] instead of [insert_area]
But then I have a new problem: there will a chance that a row in sheet 1 will be overwrited in sheet 2. I try something like this, but it returns nothing on the sheet.
function for_each_row(){
var addedsheet=SpreadsheetApp.getActive().getSheetByName("Change"); // Sheet where I want to keep the record of the change
var original_sheet = SpreadsheetApp.getActive().getSheetByName("Master"); //sheet where the change is happended
var compared_value = addedsheet.getRange(1,4).getValue(); // Cell D1 of sheet "Change", which has timestamp of today
var number_of_row_2 = addedsheet.getLastRow;
var number_of_row_1 = original_sheet.getLastRow();
for (var i=2; i<number_of_row_1 +1; i++){
var compared_stamp = original_sheet.getRange("C"+i).getValues();
var insert_values = (original_sheet.getRange(i,1,1,24).getValues())
if (compared_stamp > compared_value){
var insert_values = (original_sheet.getRange(i,1,1,24).getValues());
for (var j = 2; j<number_of_row_2 +1; j++){
var value_from_sheet = addedsheet.getRange(j,1,1,24).getValues();
if (insert_values ===value_from_sheet){
return
}
else(
addedsheet.appendRow(insert_values[0]))
}
}
}
}
My thought is if a row satisfies the 1st condition then the value will be check in sheet 2. If sheet 2 didn't have that row then append that row.
Issue:
If I understand you correctly, you want to do the following:
If sheet Master is edited, iterate through all rows in this sheet (excluding headers), and for each row, check the following:
Column C has a higher value than cell D1 in sheet Change.
This row, with these exact values, does not exist in Change.
If these conditions are meet, append the row to Change.
Solution:
Use filter and some to filter out rows that don't match your two conditions, and use setValues to write the resulting rows to your other sheet.
Code snippet:
function onEdit(e) {
var editedSheet = e ? e.range.getSheet() : SpreadsheetApp.getActiveSheet();
if (editedSheet.getName() === "Master") {
var addedSheet = SpreadsheetApp.getActive().getSheetByName("Change");
var compared_value = addedSheet.getRange(1,4).getValue();
var newData = editedSheet.getRange("A2:X" + editedSheet.getLastRow()).getValues();
var currentData = addedSheet.getRange("A2:X" + addedSheet.getLastRow()).getValues();
var filteredData = newData.filter(row => row[2] >= compared_value)
.filter(row => !currentData.some(currentRow => JSON.stringify(currentRow) === JSON.stringify(row)));
addedSheet.getRange(addedSheet.getLastRow()+1,1,filteredData.length,filteredData[0].length).setValues(filteredData);
}
}
Note:
An easy way to check if two rows have the same values is using JSON.stringify(row).
I'm assuming the timestamps are not Dates. If they are, you should compare them using getTime(). So you should change the corresponding code to newData.filter(row => row[2].getTime() >= compared_value.getTime()).

How to delete multiple cells in a sing row, and continue that for 50 rows

I'm looking to see if there is a way to delete cell A2, and then have google sheets automatically delete cells E2,G2,H2,I2. I would want this for each row for 50 rows. What is happening right now is if I delete A2, google sheets automatically pushes the next oldest data. however, it then pushes down cell E2,G2,H2,I2, because it didnt give me enough time to delete them. Help is appreciated.
https://docs.google.com/spreadsheets/d/10eK6tyHVIX6JyFChXYvtS6JmYyUnE-Ib0pClSnouBoU/edit?usp=sharing
By using a simple comparison inside your trigger you can delete the data
Here's my approach by using the code you provided inside the Sheet:
function onEdit(e){
script1(e);
script2(e);
}
function script1(e){
var row = e.range.getRow();
var col = e.range.getColumn();
if(col === 1 && row > 1 && e.source.getActiveSheet().getName() === "Kanban"){
if (e.range.getValue() === '') {
e.source.getActiveSheet().getRange(`E${row}`).setValue('');
e.source.getActiveSheet().getRange(`H${row}`).setValue('');
} else {
e.source.getActiveSheet().getRange(row,8).setValue(new Date());
}
}
}
function script2(e){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Kanban");
var range = sheet.getRange("A2:I");
range.sort([{column: 8, ascending: true}]);
}
Where if (e.range.getValue() === '') and .setValue(''); will "delete" the data when it comes to first column and it's been deleted, otherwise it'll change the Timestamp cell.
Reference
Event Object

Moving Row between sheets based on cell value

I have a workbook that I am working on for our company and need a little help on this one. Normally I can figure things out pretty easy. In my worksheet there are several tabs the ones I am working with now are NEW, In Progress, On Hold, Scheduled and Complete. Permits are added to the New tab Via google form input, what I would like to happen that when the status changes in Column K is that it goes to the corresponding tab. I had this all set up in Excel but we are no longer allowed to use Excel at work. TK's Daily Production Any help would greatly be appreciated
In sheet, click Tools > Script Editor.
Paste below code. This code assumes Column K has header 'status' and this column values have corresponding tabs = sheets in Spreadsheet. As an example, if Column K has value 'NEW', there must be a tab named 'NEW'. If you edit value in this column, say from 'NEW' to 'Complete', that row will be copied to 'Complete' tab and optionally deleted from 'NEW' tab if corresponding code is activated.
// onEdit trigger
function onEdit() {
moveToTab();
}
function moveToTab() {
// active SS
var ss = SpreadsheetApp.getActiveSpreadsheet();
// active cell/range
var range = ss.getActiveRange();
// active column
var col = range.getColumn();
Logger.log(col);
// active sheet
var aSheet = ss.getActiveSheet();
// get active column header
var header = aSheet.getRange(1,col,1,1).getValue();
Logger.log(header);
// here i assume, Column K has a header 'status'
// change 'status' string to what you have as Column K header
// if column is not 'status', do nothing
if (header.toLowerCase() !== 'status') return;
// get value
var target = range.getValue();
// trim and check there is a value
if (target.toString().trim() === '') return;
// do nothing if same sheet
if (target.toString().toLowerCase() === aSheet.getName().toLowerCase()) return;
// try {
// try move
// target sheet based on Column K value
var sheets = ss.getSheets();
var tSheet = sheets.filter(function(sheet) {
if (sheet.getName().toLowerCase() == target.toLowerCase()) return true;
else return false;
})[0];
if (!tSheet) return;
// active cell row
var row = range.getRow();
// get active row values
var values = aSheet.getRange(row, 1, 1, aSheet.getLastColumn()).getValues();
// append values to target row
tSheet.appendRow(values[0]);
// optionally delete row from old sheet
// un-comment if required
aSheet.deleteRow(row);
// } catch(e) {}
}

G-Sheets: Populate multiple cells from another sheet based on dropdown (multiple rows and columns)

I am trying to copy or populate (not sure on the correct terminology) data from multiple cells to the same sized multiple cells on another sheet based on the dropdown.
https://docs.google.com/spreadsheets/d/1ELxYcMG_kvzt6KLZoY8WyTBb3evv4dOmpYWvTlzvEVM/edit?usp=sharing
So in this spreadsheet, I'm trying to select A2 & A8 in "Results" and populate B2:I6 & B8:I12 based on the relevant rows/columns in "Data"
Is this possible?
I've done example for you to get you going, you need to implement how to ref triggering cell and get it's ref row index to do copyTo to that row index, not hardcode it like I did ..
This is the relevante code:
function onEdit(e){
// Set a comment on the edited cell to indicate when it was changed.
var range = e.range;
if( range.getA1Notation() == "A2" ){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[1];
var orgsheet = ss.getSheets()[0];
if( range.getValue() == "AAA" ){
sheet.getRange("B2:H6").copyTo(orgsheet.getRange("B2"), {contentsOnly:true});
} else if ( range.getValue() == "BBB" ) {
sheet.getRange("B8:H12").copyTo(orgsheet.getRange("B2"), {contentsOnly:true});
}
}
}
also, I think that you need to copy my sheet to your drive to be able to run the script without permission errors,
this is link to my sheet: https://docs.google.com/spreadsheets/d/1YVuQMBLEqgwGMPdjlV9cKRCML0vqi3UkMsZ66DR5Fls/edit#gid=0
cheers, k

Resources