I'm trying to modify this formula to automatically provide the definition in Column B when a word is entered in Column A. Currently, the formula looks like this...
=(index(split(concatenate(importxml("https://www.merriam-webster.com/dictionary/"&$A2,"//span[#class='dtText']")),": ",FALSE,TRUE),1,1))
This works, but it doesn't automatically provide the definition when adding new words. I tried modifying the formula using an arrayformula (seen below), but it repeats the definition for the word in A2.
={"Definition";arrayformula(if(A2:A="",,index(split(concatenate(importxml("https://www.merriam-webster.com/dictionary/"&$A2:A,"//span[#class='dtText']")),": ",FALSE,TRUE),1,1)))}
Any ideas on how to fix this? Thanks for your help. Here's the link to the Google Sheet below so you can edit it.
https://docs.google.com/spreadsheets/d/1_OrJwlOHxVXZBKA0GFaiXnRS1x5OCszrR9m3UlMuWRY/edit?usp=sharing
Thanks for your help!
According to this similar article about Use importXML from column of URLs with arrayformula returning same duplicated result in google sheet:
unfortunately, that won't do because ARRAYFORMULA does not support IMOPRTXML formulas. you could try to look up some scripted workaround for this task or give up on one cell solution
Alternative Solution
Perhaps you can use this sample onEdit(e) simple trigger script below instead via Apps Script that is bound to your Spreadsheet file:
Follow this guide on how to add the script as a bound script in your Spreadsheet file:
Sample Script:
function onEdit(e){
var sh = e.range.getSheet();
if(e.range.getColumn() != 1 || e.range.getRow() == 1) return; //ignore if you have not put the word on column A or Col #1 & on row 1
sh.getRange("B"+e.range.getRow()).setFormula("=(index(split(concatenate(importxml(\"https://www.merriam-webster.com/dictionary/"+e.range.getValue()+"\",\"//span[#class='dtText']\")),\": \",FALSE,TRUE),1,1))");
if(e.range.getValue() == "") sh.getRange("B"+e.range.getRow()).clear(); //clear column B row if the adjacent word on column A gets deleted
}
Sample Demonstration
Input the words crystal & believe on cells A2 & A3
Related
I'm trying to get the below formula to copy down column D (in red) and have the same results as column E (in green)
={"Query in H1";ARRAYFORMULA(IF(B2:B<>"",(IF(ISNUMBER(SEARCH(B3:B,IMPORTXML(A2:A,"//h1"))),"Yes","No"))))}
This formula collects the H1 (xpath) via the IMPORTXML function of the URL (column A) and checks to see if the keyword (column B) is included. If it is "Yes" if not "No"
See Google Sheet for reference:
https://docs.google.com/spreadsheets/d/1iHkU-rNtNhoOKvW_CWY7WU5OLsMFVqEFNRZlx_R-7RY/edit#gid=1497887942
Your formula just needs a few modifications:
Remove the header text and modify the SEARCH parameters to B2:B such that the formula looks like this:
=ARRAYFORMULA(IF(B2:B<>"",(IF(ISNUMBER(SEARCH(B2:B,IMPORTXML(A2:A,"//h1"))),"Yes","No"))))
Place the formula in the D2 cell.
After all the changes, this is how your sheet will look like:
I have also taken the opportunity to create a copy of the sheet named Answer with all the modifications.
As far as I know, we can not use ImportXML with ArrayFormula, the result after run formular will not correct. Even you see the result run down from the top to the last column, but the result will be wrong.
You can see an example in the screenshot below, with the same URL, the results in Column F and I are different from each other.
How to create arrayformula sequence number separated by comma in google spreadsheets
expected results is in column B
A
B
5
1,2,3,4,5
2
1,2
3
1,2,3
How about the following sample formula?
Sample formula:
=JOIN(",",ARRAYFORMULA(ROW(INDIRECT("A1:A"&A1))))
When you use this formula, please put this to a cell "B1" and drag down it.
The flow of this formula is as follows.
Create a1Notation of cells using "A1:A"&A1 using INDIRECT.
Retrieve row numbers from the a1Notation using ROW.
Join the row numbers with , using JOIN.
Result:
Note:
When you want to put all result values using one formula, unfortunately, I couldn't find the formula using the built-in functions. In that case, I would like to propose to a custom function as follows. When you use this, please copy and paste the following script to the script editor of Spreadsheet.
And, please put a formula of =SAMPLE(A1:A) to a cell "B1". By this, the result values are put to the column "B" using the values of column "A".
const SAMPLE = v => v.map(([e]) => e && !isNaN(e) ? [...Array(e)].map((_, i) => i + 1).join(",") : "");
References:
INDIRECT
ROW
JOIN
Custom Functions in Google Sheets
You can use TEXTJOIN() with SEQUENCE() function.
=TEXTJOIN(",",TRUE,SEQUENCE(A1))
You can also use this functions in desktop Excel365
To start, this is my first time posting and so please let me know if I can fix my post in any way to make it easier to answer.
I am trying to create an auto-expanding array formula
I have a sheet with my investment asset mix that including amounts of shares owned of each particular stock, and a sheet that tracks when I receive dividends. My goal is to write an automatically expanding array formula that will sum up the amount of shares that own of a stock on the date a dividend is received and return that value. I have written three different formulas that all accomplish this but none of them will auto-expand as an array.
I'm sure there are a lot of solutions I've overlooked. To boil it down, I need an expanding array formula that will sum the "Shares" column of my asset mix sheet ('Asset Mix'!D2:D, or 'AssetMixShares') conditionally. The name of the stock entered in 'Dividends'!C2:C needs to match the name of the stock in 'Asset Mix'!A2:A (or the named range 'AssetMixStocks'). It then needs to check the dates in 'Asset Mix'!C2:C (or 'AssetMixDates') against the dates in 'Dividends'!A2:A and sum all share amounts where the purchase date is less than (earlier than) the Ex-Dividend Date.
I could probably write some sort of vlookup array on the "Running Total" column -- 'Asset Mix'!E:E -- that would solve the issue, but I'm hoping to eliminate that column. I feel very strongly that what I'm trying to do should be possible without the help of a running total column -- I just don't have the knowledge.
I have tried countless functions and formulas, but the four that I currently have in my example worksheet are SUM, SUMPRODUCT, DSUM, and QUERY.
Attempt 1
SUM and IF
=ArrayFormula(SUM(IF('Asset Mix'!A:A=C2,IF('Asset Mix'!C:C<A2,'Asset Mix'!D:D))))
Attempt 2
SUMPRODUCT
=({arrayformula(SUMPRODUCT(--((AssetMixStock=(indirect("C"&ROW())))*(AssetMixDate<(indirect("A"&ROW())))),AssetMixShares))})
Attempt 3
DSUM
=DSUM('Asset Mix'!A:E,"Shares",{"Date","Stock";"<"&A2,C2})
Attempt 4
QUERY
=arrayformula(query(AssetMix,"Select sum(D) where A = '"&C2:C&"' and C < date'"&(text(year(A2:A),"0000") & "-" & text(month(A2:A),"00") & "-" & text(day(A2:A),"00"))&"' label sum(D) ''",0))
These will all work, as long as I manually drag the formula down, but I want to write some sort of formula that will auto-expand to the bottom of the Dividends sheet.
I have tried to create a Dummy sheet that has both of the relevant sheets. Please let me know if you can access it -- the link is below.
https://docs.google.com/spreadsheets/d/1wlKffma0NJ0KrlWxyX_N20y62azsGpFp3enhmjzJK1Q/edit?usp=sharing
Thanks so much for getting this far and any help you can provide!
We can focus in the first formula to understand a way to make it "self-expandable". As we see it contains references to the cells A2 and C2 in "Dividends" sheet:
=ArrayFormula(SUM(IF('Asset Mix'!A:A=C2,IF('Asset Mix'!C:C<A2,'Asset Mix'!D:D))))
Every time some data appears in these columns (A and C), the formula should work. We can control the presence of the formula by onEdit trigger, if editing is manual. Consider the code:
function onEdit(e) {
var sheet = SpreadsheetApp.getActive().getActiveSheet();
if (sheet.getName() == 'Dividends') {
var row = e.range.getRow();
for (var offset = 0; offset < e.range.getHeight(); offset++) {
sheet.getRange(3, 10).copyTo(sheet.getRange(row + offset, 10));
}
}
}
It checks any modification on the sheet "Dividends" and copies required formula to the modified row(s). This way the formula is expanded for other rows in use.
Well, it's solved! I'll leave this up in case anyone else has the same question.
A kind soul explained the magic of MMULT() to me, and wrote this solution.
=ARRAYFORMULA(MMULT((C2:C=TRANSPOSE('Asset Mix'!A2:A))*(A2:A>TRANSPOSE('Asset Mix'!C2:C)),N('Asset Mix'!D2:D))
Google Sheets script for if/then statement
Can someone help me write a script for the following:
I need my Google Sheet to input "No" in column W if column J has the word "transfer" in it. Otherwise, it needs to input "N/A".
I currently have the following formula in my Google spreadsheet:
=IF(ISERROR(SEARCH("transfer",J2,1)),"N/A","No")
but as you know, the formula is cleared out once it gets a new entry from the linked Google form.
Any help would be tremendously appreciated.
This might restore your formula. Try attaching it to the form submit trigger.
function fallingFromTheSky(e)
{
var row=e.range.getRow();
e.range.getSheet().getRange(row,23).setFormula('=IF(ISERROR(SEARCH("transfer",J'+ row +',1)),"N/A","No")');
}
How do I copy data from one cell of a column to next cell of next column if the data is greater than 2 by using formula?
Now my file is like this:
I want to transfer the data from column B to column C, whose value > than 2.
So, the sheet will be like this:
Please help me to solve this... Thank You.
You can copy the values over if they are greater than or equal to five, but moving them is not something you can do with a custom function, you would need apps script running to do that for you.
Here is what you can do: =IF(B2 > 2, B2, "") , this will copy the value over if its > 2. Just drag this formula down the sheet.
I have also added basic conditional formatting to highlight it as red.
Example Sheet
try this formula:
=ArrayFormula(
{sheet1!A2:A,
if(sheet1!B2:B<=2,sheet1!B2:B,""),
if(sheet1!B2:B>2,sheet1!B2:B,"")})
use it in separate sheet to convert existing table(1) to result table(2) from yuor example.