I will try to be as clear as possible. Here is the example piece: link
What I want to happen is that the Filter formula will search for any Sheet containing “Form Responses” and then display the results. You can see on the Current sheet how I’ve been doing, but this is more tedious and leads to issues of the first formula begins to overwrite the next one, etc. On the Wanted tab, I’ve laid out how I imagine it and put a note in A7. Any help offered is greatly appreciated!
You can get started with this script:
function getSheetResponses(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Wanted");
var getCellValue = sheet.getRange("A7").getValue(); //Gets the name of your designated sheet on "Wanted Sheet" cell "A7"
var getName = ss.getSheetByName(getCellValue);
var getNameValue = getName.getRange(2,5,getName.getLastRow(),1).getValues(); //Gets all the values of Column E on any defined sheet names based on getCellValue
var datalength = getNameValue.length;
Logger.log(datalength);
sheet.getRange(8,6,datalength,1).setValues(getNameValue); //Puts the data on Wanted Sheet Column F
}
What this does is it gets the sheet name on cell A7, and populates the data on Column F row 8 on the "Wanted" sheet like so:
Now, the data it populates on the "Wanted" sheet came from Form Responses 1 based on the sample piece you have provided:
If ever you would want to relocate which specific row or column the data would be pasted on "Wanted" Sheet. You can refer to this documentation on how to modify the rows and columns on sheet.getRange()
Reference:
https://developers.google.com/apps-script/reference/spreadsheet/sheet#getrangerow,-column,-numrows,-numcolumns
please refer to the images below
Sheet1
sheet2
I have 2 sheets: sheet1 and sheet2, here's what I want to do: if sheet2!B37 = sheet1!B1, take the value of sheet1!B2, if not stay blank.
This part is easy, but what I want is that if I change the date in sheet1!B1 to 16 Mar 2021 and sheet1!B2 to 90, I want sheet2!C37 to stay 100 and sheet2!C38 returns 90.
One way is to copy the content of sheet2!C37 and paste it as value.
Reference: Convert formulas to values in Google Sheets
But I doubt that you would want to convert the formula into a value every time you need to change the condition. Hence, you might want to consider using Google Apps Script and run it using a button.
Sample Code:
function updatePrice() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
//Get Sheet1 object
var sheet1 = ss.getSheetByName("Sheet1");
//Get Sheet1 object
var sheet2 = ss.getSheetByName("Sheet2");
//Get Sheet1!B1 string value
var targetDate = sheet1.getRange("B1").getDisplayValue();
//Get Sheet1!B2 string value
var targetPrice = sheet1.getRange("B2").getDisplayValue();
//Get Sheet2 column B range
var dates = sheet2.getRange("B1:B");
//Create a textfinder and look for the target date (Sheet1!B1 value)
var textFinder = dates.createTextFinder(targetDate);
var firstOccurrence = textFinder.findNext();
if(firstOccurrence!=null){
//Date found
//Update price in column C
firstOccurrence.offset(0,1).setValue(targetPrice);
}
}
What it does?
Get the active spreadsheet using SpreadsheetApp.getActiveSpreadsheet()
Get the sheet object for Sheet1 and Sheet2 using Spreadsheet.getSheetByName(name)
Select the range for Sheet1!B1 and Sheet1!B2 using Sheet.getRange(a1Notation). Get the string value using Range.getDisplayValue()
Select the range for Sheet2!B1:B using [Sheet.getRange(a1Notation)]
Create a textFinder using Range.createTextFinder(findText)
Get the first occurrence of the date string that was being searched using TextFinder.findNext(). If date string has no match, return will be null. If date string has match it will return a Range of the matching cell
Matching cell will give you a range in column B, to set the price value move the range 1 column to the right by adding 1 column offset using Range.offset(rowOffset, columnOffset) and set the range value using Range.setValue(value)
Add A Google Sheets Button To Run Scripts
Add a Google Sheets button. You add a button via the Insert > Drawing menu.
Click Save and Close, this drawing gets added to your Google Sheet. You can right click on it to resize it or drag it around to reposition it.
To assign a script, Right Click the drawing and click the three little dots in the top right of the drawing and select Assign Script. Then type in the name of the function you want to run from your Apps Script code.
Output:
Note:
Please don't forget to click enter when editing your Sheet1 values before clicking the button. Apps Script cannot update Sheet2 when the cell to be read is still in edit.
I have a spreadsheet with say following page names:
"Sheet 1"
"Sheet 2"
"Sheet 3"
Afterwards, I changed name of
"Sheet 1" -> "Rough"
Is there anyway for me to get a list of all page names of the file in a spreadsheet page in a column?
Issue:
You want to trigger an action when a sheet name is modified (sheet here refers to a tab, or to a page, as you seem to call it). Sheets formulas will not get triggered by a sheet name change.
Solution:
You can accomplish this by installing an Apps Script onChange trigger, which will fire a function you specify when the spreadsheet's content or structure is changed (e.g., when a sheet name is changed). To do this, you can follow these steps:
In your spreadsheet, select Tools > Script editor to open a script bound to your file.
Create an Apps Script function to do the following: (1) retrieve all the sheet names, (2) write these sheet names to a specified sheet. You could use this function, for example. Copy it to the script editor and save the project:
function onChangeTrigger() {
var ss = SpreadsheetApp.getActive(); // Get current spreadsheet
var sheetNames = ss.getSheets().map(sheet => [sheet.getName()]); // Get sheet names
var destSheet = ss.getSheetByName("All Tab Names"); // Change according to your preferences
destSheet.getRange("A2:A").clearContent(); // Remove previous content
destSheet.getRange(2, 1, sheetNames.length).setValues(sheetNames);
}
Install the onChange trigger to fire the function above, either manually, following these steps, or programmatically, by running this function once:
function createOnChangeTrigger() {
var ss = SpreadsheetApp.getActive();
ScriptApp.newTrigger("onChangeTrigger")
.forSpreadsheet(ss)
.onChange()
.create();
}
Note:
The function onChangeTrigger writes all sheet names to column A of a sheet called All Tab Names. Please change that to your sheet name. Also, check this if you want to change the range to which the sheet names are written.
Reference:
onChange trigger
You could install this Addon Formulas to use one of its functions =UTIL_SHEETNAME() within a cell of all your sheets (let say in A1 of every tab), then you would have a master sheet for listing your tabs and where you reference each formula you've used (=Sheet1!A1; =Sheet2!A1; etc...). But this function doesn't seem to update quickly though.
Alternatively, you could write a code (Apps Script) to list all your tabs, which has been answered everywhere. If you need help with the latter, add in your tags 'Google-Apps-Script' to add more visibility to your question.
I saw several complains about the delay of updating data through IMPORTRANGE in Google Sheets but I need the opposite and don't want the second sheet to get updated automatically, just update at the end of the day for example.
The code is already like this:
=IMPORTRANGE("The Key","The_Page!B:D")
I hacked around this by, on both spreadsheets by creating a refresh loop using a NOW cell, with both spreadsheets crossreferencing each other's NOW cell.
When the original sheet gets appended with a form submission or something, it updates its own NOW cell, and reupdates own IMPORTRANGE cell. The second spreadsheet follows suit, updating its own NOW cell to provide the original sheet with the correct data. Because the second spreadsheet has updated itself, it also updates the main IMPORTRANGE which refreshes the data you want it to display in the first place, as well as the IMPORTRANGE cell which gets the NOW cell from the original spreadsheet
At least, I'm pretty sure that's how it works. All I know, and all I care about, frankly, is that it works
Maybe you need to use the script editor and write a simple function of the kind:
function importData()
{
var ss = SpreadsheetApp.getActiveSpreadsheet(); //source ss
var sheet = ss.getSheetByName("The_Page"); //opens the sheet with your source data
var values = sheet.getRange("B:D").getValues(); //gets needed values
var ts = SpreadsheetApp.openById("The Key"); //target ss - paste your key
ts.getSheetByName("Name of the target sheet").getRange("B:D").setValues(values);
}
And then add a time-driven trigger to this project (Resources > Current project's triggers > Add a new one).
I am looking for formula for google spreadsheet
highlight cell if value duplicate in same column
can anyone please assist me for this query?
Try this:
Select the whole column
Click Format
Click Conditional formatting
Click Add another rule (or edit the existing/default one)
Set Format cells if to: Custom formula is
Set value to: =countif(A:A,A1)>1 (or change A to your chosen column)
Set the formatting style.
Ensure the range applies to your column (e.g., A1:A100).
Click Done
Anything written in the A1:A100 cells will be checked, and if there is a duplicate (occurs more than once) then it'll be coloured.
For locales using comma (,) as a decimal separator, the argument separator is most likely a semi-colon (;). That is, try: =countif(A:A;A1)>1, instead.
For multiple columns, use countifs.
While zolley's answer is perfectly right for the question, here's a more general solution for any range, plus explanation:
=COUNTIF($A$1:$C$50, INDIRECT(ADDRESS(ROW(), COLUMN(), 4))) > 1
Please note that in this example I will be using the range A1:C50.
The first parameter ($A$1:$C$50) should be replaced with the range on which you would like to highlight duplicates!
to highlight duplicates:
Select the whole range on which the duplicate marking is wanted.
On the menu: Format > Conditional formatting...
Under Apply to range, select the range to which the rule should be applied.
In Format cells if, select Custom formula is on the dropdown.
In the textbox insert the given formula, adjusting the range to match step (3).
Why does it work?
COUNTIF(range, criterion), will compare every cell in range to the criterion, which is processed similarly to formulas. If no special operators are provided, it will compare every cell in the range with the given cell, and return the number of cells found to be matching the rule (in this case, the comparison). We are using a fixed range (with $ signs) so that we always view the full range.
The second block, INDIRECT(ADDRESS(ROW(), COLUMN(), 4)), will return current cell's content. If this was placed inside the cell, docs will have cried about circular dependency, but in this case, the formula is evaluated as if it was in the cell, without changing it.
ROW() and COLUMN() will return the row number and column number of the given cell respectively. If no parameter is provided, the current cell will be returned (this is 1-based, for example, B3 will return 3 for ROW(), and 2 for COLUMN()).
Then we use: ADDRESS(row, column, [absolute_relative_mode]) to translate the numeric row and column to a cell reference (like B3. Remember, while we are inside the cell's context, we don't know it's address OR content, and we need the content in order to compare with). The third parameter takes care for the formatting, and 4 returns the formatting INDIRECT() likes.
INDIRECT(), will take a cell reference and return its content. In this case, the current cell's content. Then back to the start, COUNTIF() will test every cell in the range against ours, and return the count.
The last step is making our formula return a boolean, by making it a logical expression: COUNTIF(...) > 1. The > 1 is used because we know there's at least one cell identical to ours. That's our cell, which is in the range, and thus will be compared to itself. So to indicate a duplicate, we need to find 2 or more cells matching ours.
Sources:
Docs Editors Help: COUNTIF()
Docs Editors Help: INDIRECT()
Docs Editors Help: ADDRESS()
Docs Editors Help: ROW()
Docs Editors Help: COLUMN()
Answer of #zolley is right. Just adding a Gif and steps for the reference.
Goto menu Format > Conditional formatting..
Find Format cells if..
Add =countif(A:A,A1)>1 in field Custom formula is
Note: Change the letter A with your own column.
From the "Text Contains" dropdown menu select "Custom formula is:", and write: "=countif(A:A, A1) > 1" (without the quotes)
I did exactly as zolley proposed, but there should be done small correction: use "Custom formula is" instead of "Text Contains".
And then conditional rendering will work.
Highlight duplicates (in column C):
=COUNTIF(C:C, C1) > 1
Explanation: The C1 here doesn't refer to the first row in C. Because this formula is evaluated by a conditional format rule, instead, when the formula is checked to see if it applies, the C1 effectively refers to whichever row is currently being evaluated to see if the highlight should be applied. (So it's more like INDIRECT(C &ROW()), if that means anything to you!). Essentially, when evaluating a conditional format formula, anything which refers to row 1 is evaluated against the row that the formula is being run against. (And yes, if you use C2 then you asking the rule to check the status of the row immediately below the one currently being evaluated.)
So this says, count up occurences of whatever is in C1 (the current cell being evaluated) that are in the whole of column C and if there is more than 1 of them (i.e. the value has duplicates) then: apply the highlight (because the formula, overall, evaluates to TRUE).
Highlight the first duplicate only:
=AND(COUNTIF(C:C, C1) > 1, COUNTIF(C$1:C1, C1) = 1)
Explanation: This only highlights if both of the COUNTIFs are TRUE (they appear inside an AND()).
The first term to be evaluated (the COUNTIF(C:C, C1) > 1) is the exact same as in the first example; it's TRUE only if whatever is in C1 has a duplicate. (Remember that C1 effectively refers to the current row being checked to see if it should be highlighted).
The second term (COUNTIF(C$1:C1, C1) = 1) looks similar but it has three crucial differences:
It doesn't search the whole of column C (like the first one does: C:C) but instead it starts the search from the first row: C$1
(the $ forces it to look literally at row 1, not at whichever row is being evaluated).
And then it stops the search at the current row being evaluated C1.
Finally it says = 1.
So, it will only be TRUE if there are no duplicates above the row currently being evaluated (meaning it must be the first of the duplicates).
Combined with that first term (which will only be TRUE if this row has duplicates) this means only the first occurrence will be highlighted.
Highlight the second and onwards duplicates:
=AND(COUNTIF(C:C, C1) > 1, NOT(COUNTIF(C$1:C1, C1) = 1), COUNTIF(C1:C, C1) >= 1)
Explanation: The first expression is the same as always (TRUE if the currently evaluated row is a duplicate at all).
The second term is exactly the same as the last one except it's negated: It has a NOT() around it. So it ignores the first occurence.
Finally the third term picks up duplicates 2, 3 etc. COUNTIF(C1:C, C1) >= 1 starts the search range at the currently evaluated row (the C1 in the C1:C). Then it only evaluates to TRUE (apply highlight) if there is one or more duplicates below this one (and including this one): >= 1 (it must be >= not just > otherwise the last duplicate is ignored).
I tried all the options and none worked.
Only google app scripts helped me.
source : https://ctrlq.org/code/19649-find-duplicate-rows-in-google-sheets
At the top of your document
1.- go to tools > script editor
2.- set the name of your script
3.- paste this code :
function findDuplicates() {
// List the columns you want to check by number (A = 1)
var CHECK_COLUMNS = [1];
// Get the active sheet and info about it
var sourceSheet = SpreadsheetApp.getActiveSheet();
var numRows = sourceSheet.getLastRow();
var numCols = sourceSheet.getLastColumn();
// Create the temporary working sheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
var newSheet = ss.insertSheet("FindDupes");
// Copy the desired rows to the FindDupes sheet
for (var i = 0; i < CHECK_COLUMNS.length; i++) {
var sourceRange = sourceSheet.getRange(1,CHECK_COLUMNS[i],numRows);
var nextCol = newSheet.getLastColumn() + 1;
sourceRange.copyTo(newSheet.getRange(1,nextCol,numRows));
}
// Find duplicates in the FindDupes sheet and color them in the main sheet
var dupes = false;
var data = newSheet.getDataRange().getValues();
for (i = 1; i < data.length - 1; i++) {
for (j = i+1; j < data.length; j++) {
if (data[i].join() == data[j].join()) {
dupes = true;
sourceSheet.getRange(i+1,1,1,numCols).setBackground("red");
sourceSheet.getRange(j+1,1,1,numCols).setBackground("red");
}
}
}
// Remove the FindDupes temporary sheet
ss.deleteSheet(newSheet);
// Alert the user with the results
if (dupes) {
Browser.msgBox("Possible duplicate(s) found and colored red.");
} else {
Browser.msgBox("No duplicates found.");
}
};
4.- save and run
In less than 3 seconds, my duplicate row was colored. Just copy-past the script.
If you don't know about google apps scripts , this links could be help you:
https://zapier.com/learn/google-sheets/google-apps-script-tutorial/
https://developers.google.com/apps-script/overview
I hope this helps.