IFS Formula in Google Sheets - if-statement

I am looking for a formula in Google Sheet.
The formula is based on an "Imput" sheet and "Output" sheet. In the "Imput" sheet there are following columns:
current_position, company_name, current_position_2, current_company_2
In the "Output" sheet there are "Title" and "Account name" Imput + Output
The formula should be in "Title" in "Output" and say:
1)
If "current_position" contains "COO", "CEO", "CSO" (and a lot more titles) then take "company_name" and put in "Account Name" under "Output".
2)
If "current_position" does not contain "COO", "CEO", "CSO" (and a lot more titles) AND "current_position_2" contain "COO", "CEO", "CSO" (and a lot more titles) then put "current_position_2" in "Title" in "Output" and "current_company_2" in "Account Name" in "Output"
3)
If neither of "current_position" or "current_position_2 contains "COO", "CEO", "CSO" (and a lot more titles) then take "current_position" and put in "Title" under "Output" and "Current_position_2" and put in "Account Name" in "Output"

Note:
As much as possible, make sure to include what you have done so far or share any research you've done to make sure you're posting a good question.
Recommendation:
On my testing, the IFS Function is quite limited to achieve your goal to set up values to different columns based on multiple conditions.
I have come up with an alternative solution by creating a custom function that checks all values on the 'Imput' sheet and returns the values on 'Output' sheet based on the 3 conditions you've described above:
UPDATED Script:
function onOpen() { // to refresh
SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Output').getRange('C2').setValue("=checkImput()");
}
function checkImput(){
var imput = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Imput');
var row = imput.getDataRange().getNumRows();
var res = [];
for(var x=2; x<=row; x++){
var current_position = imput.getRange(x,7).getValue();
var current_position2 = imput.getRange(x,43).getValue();
var positions = "COO,CEO,CSO"; //Add new postion separated by comma
if(positions.includes(current_position)){ // If "courrent_position" contains "COO", "CEO", "CSO"
res.push([current_position,imput.getRange(x,8).getValue()]); //Then put "current_position" in "Title" and "current_company" in Account Name
}else{
if(positions.includes(current_position2)){ //If "current_position" does not contain "COO", "CEO", "CSO" (and a lot more titles) AND "current_position_2" contain "COO", "CEO", "CSO"
res.push([current_position2,imput.getRange(x,44).getValue()]); //Then put "current_position_2" in "Title" in "Output" and "current_company_2" in "Account Name" in "Output"
}else{ //If neither of "current_position" or "current_position_2 contains "COO", "CEO", "CSO" (and a lot more titles)
res.push([current_position2,imput.getRange(x,44).getValue()]); //Then take "current_position" and put in "Title" under "Output" and "Current_position_2" and put in "Account Name" in "Output"
}
}
}
return res;
}
Here's the sample 'Imput' sheet I've tested:
Result on 'Output' sheet:

Related

Google Sheet Conditional Formatting highlight 2 columns if one column contain certain text of 5 columns

In Google Sheet, I want to highlight only 2 columns out of 5 columns.
5 columns here but I want to highlight only 'Name' and 'Weight' columns if a cell contain the word 'Smith'
The outcome should be like this.
I want to input more name and if the name contain the word 'Smith', I want it to be automatically highlighted for name and weight columns.
I tried to use conditional formatting in Google sheet, and I could highlight only the name column.
This is what I tried.
Outcome was this.
You are not far, try the following formula in the conditional formatting:
=IF(REGEXMATCH($C3, "Smith"), 1, 0)
The formula given by #nabais works.
In conditional formatting though one does not need to use the starting IF function.
"Format cells if" is how conditional formatting rules are formed by default as noted in the official help page.
Create a rule.
Single color: Under "Format cells if," choose the condition that you want to trigger the rule. Under "Formatting style, choose what the
cell will look like when conditions are met.
Color scale: Under "Preview," select the color scale. Then, choose a minimum and maximum value, and an optional midpoint value. To choose
the value category, click the Down arrow Down Arrow.
So the following formula is all that is needed:
(Please adjust ranges to your needs)
=REGEXMATCH($G2, "Smith")
You can try the following code:
function highlight() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var data = ss.getRange('A1:E').getValues();
for (i = 1; i < data.length; i++) {
var tf = ss.getRange("B" + i).createTextFinder('smith');
tf.matchEntireCell(false);
tf.matchCase(false);
var result = tf.findNext();
if (result !== null) {
var range = result.getRow();
ss.getRange('B' + range).setBackground('Yellow');
ss.getRange('D' + range).setBackground('Yellow');
}
};
};

Issue with multiple conditions in script editor

I've created a script editor for a google sheet that has multiple tabs. One if statement I can't seem to get working is - If sheet "Employee Evolution" column 8 EQUALS "Disqualified" AND column 13 is NOT EQUAL to "NO DATA", move the row to sheet "Disqualified" I've tried so many different ways to rearrange and can't get it to work.
**function onEdit(event) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(s.getName() == "Employee Evolution" && r.getColumn() == 8 && r.getValue() == "Disqualified" && r.offset.getValue(0,5) != "NO DATA") {
var row = r.getRow();
var numColumns = s.getLastColumn();
var targetSheet = ss.getSheetByName("Disqualified");
var target = targetSheet.getRange(targetSheet.getLastRow() + 1, 1);
s.getRange(row, 1, 1,numColumns).moveTo(target);
s.deleteRow(row);**
I have no coding experience, so I'm having a difficult time understanding javascript documents that explain this stuff. Please help!
Below is the link to my spreadsheet
https://docs.google.com/spreadsheets/d/1vp46hMbmB5968cRW2BGhS66qqNhl91Llk8xeknlRuQc/edit#gid=0
Right now I only have the first if statement and else if statement set up with multiple conditions, but that is not working. When I populate the 8th column (H) with Disqualified and populate the 13th column (M) with anything at all, nothing happens. And, if I populate column H with Qualified and populate column M with Paid Search, nothing happens.
Basically I want the row to move to either the PPC tab or the Disqualified tab. However, I don't want the row to move until both columns H and M are populated with specific text. If column H says "Qualified" AND column M says "Paid Search" the row should move to the PPC tab. If column H says "Disqualified" AND column M says anything other than NO DATA (even Paid Search), the row should move to the Disqualified tab.
The problem I can't get past is that I need to have each if statement look at both columns before executing true.
I hope this makes sense and thank you for your help.
It's not possible to define if that if should be working or not based just on the code as we don't have that spreadsheet you're using.
But I do notice some things that maybe are wrong on yout assumptiong, for this break that if into :
s.getName() == "Employee Evolution" => Checks if the current sheet that you have active is called "Employee Evolution"
r.getColumn() == 8 => checks if the current column that you have active is column number 8 (column h)
r.getValue() == "Disqualified" => checks if the current cell that you have active is equal to Disqualified (must matcha case as well)
r.offset.getValue(0,5) != "NO DATA") => Checks if column offset by 5 (will be equal column 13 indeed) is different then "NO DATA" (also must match case)
And of course as this function is onEdit, so this code will only run when you change something on the spreadsheet.
So I suppose by reading that code is that whenever someone changes column 8 to "Disqualified" (must match the capital letters as well) and all the other criterias match, it should be moved to "Disqualified" sheet. Pay attention to all the case sensitive scenarios you have.
I think overall the code seems fine. Share the spreadsheet so we can check what might be going wrong.
PS: by something being active I mean that your cursor is clicked/selected that thing

Why is my Applescript IF Loop and "Equals To" operator not working properly?

I have an applescript Progress Bar Simulator and I have the user select a menu item from a list:
set gameMenuOption to choose from list simMenu with prompt "
Slot: " & item slot of gameslots & "
Mulla: $" & gameMulla & "
Assets: " & gameAssets & "
Speed: " & gameLoadSpeed & "Assets Per Second"
The prompt is basically the user's assets, money, etc. So when they select something from the menu, they can also take a look at their stats. So when they select something, it processes the input:
if gameMenuOption = "Shop" then
set gameShopOption to choose from list simShop with prompt "Shop: "
else if gameMenuOption is equal to "Load Progress Bar" then
--not finished yet!
else if gameMenuOption is equal to "Sell Assets" then
set gameMulla to gameMulla + gameAssets
else
error -128
end if
The if statement doesn't work! I have researched the syntax of an IF loop on applescript and operators and re-read my code over and over again but I don't see any errors! When the user selects an option, it just returns the -128 error that I purposely wrote but It isn't supposed to do that... I even tested it with display dialog:
--> User enters: Sell Assets
display dialog gameMenuOption
--> Returns: Sell Assets
But when I do this:
display dialog gameMenuOption = "Sell Assets"
--> Returns: False
Also, I thought I needed to convert it to a string but that didn't work:
Expected expression but found “to”.
Please help me!
From the docs:
The choose from list command can optionally let the user choose multiple items by setting the multiple selections allowed parameter to true. For this reason, the result of the command is always a list of selected strings.
So the result will never be "Shop". It might be {"Shop"}.
Example:
set simMenu to {"Shop", "Sell Assets"}
set gameMenuOption to choose from list simMenu with prompt "Blah blah blah"
if gameMenuOption = {"Shop"} then
display dialog "It worked" // the dialog appears
end if
Or (this is probably more usual) you could say
if item 1 of gameMenuOption = "Shop"

Removing a row containing a specific text in Google Sheets

I have a data set of around 3000 columns, but some of the columns have several cells that contain cells "na". These rows have no importance since they don't have data that I will need, is there a command in google sheets that can either highlight the entire row that contains that text or delete the entire row containing that text?
Any help would be appreciated.
https://docs.google.com/spreadsheets/d/1u8OUfQOzgAulf1a8bzQ8SB5sb5Uvb1I4amF5sdGEBlc/edit?usp=sharing
My document ^.
you can use this formula to color all na rows:
=ARRAYFORMULA(REGEXMATCH(TRANSPOSE(QUERY(TRANSPOSE($A1:$Z),,999^99)), " na "))
This answer based on what I understand, sorry if I'm wrong. You can use conditional formatting to highlight all NA text
This is what rules I used
Here are another answers that may help you
Delete a row in Google Spreadsheets if value of cell in said row is 0 or blank
Google Sheets: delete rows containing specified data
Deleting Cells in Google Sheets without removing a whole row
Sorry for bad English.
I'm not sure if my understing is well but see below what you can do.
This is a google script function which color the whole column where "na" is in
function myFunction() {
//get the spreadsheet where the function is running
var ss = SpreadsheetApp.getActive()
//Replace "the name of your sheet" by your sheet name" be careful its case sensitive.
var sheet = ss.getSheetByName("The name of your sheet")
//Get all your data as an array (If your sheet has no header, change 2 by 1 and (sheet.getLastRow()-1) by sheet.getLastRow())
var values = sheet.getRange(2,1,(sheet.getLastRow()-1), sheet.getLastColumn()).getValues();
//For each column
for (var i = 0; i< sheet.getLastColumn(); i++){
//using function map is helping to select one column by one column
var mapValues = values.map(function(r){return r[i]});
//Searching your keyword in the column, in your case it's "na"
var position = mapValues.indexOf("Put the string that you are looking for, in your case 'na'");
//if at least there is one "na" inside the column
if( position >-1){
//then this color have to get red color as a background
var wholeColumn = sheet.getRange(2,(i+1),(sheet.getLastRow()-1));
wholeColumn.setBackground("red");
}
}
}``
Let me know if it works

Assigning values to a list of variables without using an if statement in Applescript

This question seems to have been covered before in other languages, but I can't seem to locate one in applescript. I'm making a script that allows me to bring up a menu and select a website to go to. I currently have it working, but it uses an if statement to go through every possible option to see if that's the one I chose -- you can see below:
set theDestinations to {"Agorapulse", "Applescript Error Guide", "Budget Template", "Chinese Dictionary", "FNBG Email", "Key Codes", "Slacker", "Verbling - Chinese", "Verbling - Russian"} as list
set theChosenDestination to choose from list theDestinations with prompt "Where do you want to go?" default items {"Agorapulse"}
set theChosenDestination to (get item 1 of theChosenDestination)
tell application "System Events"
if (theChosenDestination = "Agorapulse") then
set theURL to "https://app.agorapulse.com/"
else if (theChosenDestination = "Applescript Error Guide") then
set theURL to "http://krypted.com/lists/comprehensive-list-of-mac-os-x-error-codes/"
else if (theChosenDestination = "Budget Template") then
set theURL to "https://docs.google.com/spreadsheets/d/1X4Yso2DgTbJq_c807_gQhuZBNa5sKtYc1VYEzHfZVnU/edit#gid=1442879437"
else if (theChosenDestination = "Chinese Dictionary") then
set theURL to "https://www.mdbg.net/chinese/dictionary?page=worddict&wdrst=0&wdqb=hedgehog"
else if (theChosenDestination = "FNBG Email") then
set theURL to "https://mail.google.com/mail/u/0/#label/FNBGames"
else if (theChosenDestination = "Key Codes") then
set theURL to "https://eastmanreference.com/complete-list-of-applescript-key-codes"
else if (theChosenDestination = "Slacker") then
set theURL to "https://slacker.nathanhoad.net/fnbgames"
else if (theChosenDestination = "Verbling - Chinese") then
set theURL to "https://www.verbling.com/lesson/5c9007a743a3330007554ad8"
else if (theChosenDestination = "Verbling - Russian") then
set theURL to "https://www.verbling.com/lesson/5c9b354fd50da2000708901a"
else if (theChosenDestination = "Other") then
set theURL to text returned of (display dialog "Enter the URL of the target website:" default answer "")
else
display dialog "no match"
end if
end tell
tell application "Google Chrome"
activate
open location theURL
end tell
Like I said, it works, and given the light work it has to do it operates plenty fast, but it is inelegant. I look at that long list.
What I'd really like to be able to do is something like I've seen in other languages, something like a list of {("Agorapulse", "https://app.agorapulse.com"),(...)}, but I've fiddled about and can't seem to make it work. Any thoughts or help would be greatly appreciated.
(oh, also, I had to beat the code about the head and shoulders a bit to get the list choices and the checks in the if statement to be of the same class so they'd talk to each other. I think I did an OK job of that, but feel free to critique :)
Use two lists, adding the index prefix is more efficient.
set theDestinations to {"1 Agorapulse", "2 Applescript Error Guide", "3 Budget Template", "4 Chinese Dictionary", "5 FNBG Email", "6 Key Codes", "7 Slacker", "8 Verbling - Chinese", "9 Verbling - Russian", "10 Other…"}
set theURLs to {"https://app.agorapulse.com/", "http://krypted.com/lists/comprehensive-list-of-mac-os-x-error-codes/", "https://docs.google.com/spreadsheets/d/1X4Yso2DgTbJq_c807_gQhuZBNa5sKtYc1VYEzHfZVnU/edit#gid=1442879437", "https://www.mdbg.net/chinese/dictionary?page=worddict&wdrst=0&wdqb=hedgehog", "https://mail.google.com/mail/u/0/#label/FNBGames", "https://eastmanreference.com/complete-list-of-applescript-key-codes", "https://slacker.nathanhoad.net/fnbgames", "https://www.verbling.com/lesson/5c9007a743a3330007554ad8", "https://www.verbling.com/lesson/5c9b354fd50da2000708901a"}
set theChosenDestination to choose from list theDestinations with prompt "Where do you want to go?" default items {"1 Agorapulse"}
if theChosenDestination is false then return
set chosenIndex to (word 1 of item 1 of theChosenDestination) as integer
if chosenIndex < 10 then
set theURL to item chosenIndex of theURLs
else
set theURL to text returned of (display dialog "Enter the URL of the target website:" default answer "")
end if