How do I address the current cell in a formula vs typing in the cell name (Ex: A2)? - google-sheets-formula

I'm using the =IMPORTRANGE formuala to pull values from another spreadsheet and represent them in a comparison chart on another sheet. Here is the formula below.
=IMPORTRANGE("the link to my doc is here", "Wed. HEADCOUNT!C2")
^^^ this formula currently works. What I'd like to do is replace C2 with "currentcell" but this breaks the formula. I need to do this to repaste the formula hundreds of times without having to individually change each one.
Any thoughts?
I've tried putting in "currentcell", but this led to #REF error.

You can create a "virtual" reference to your current cell by using CELL("address",C2), which returns the address "C2", and then C2 will move when you copy the cell to another location.
So your formula will be this:
=IMPORTRANGE("the link to my doc is here", "Wed. HEADCOUNT!" & CELL("address",C2))

Related

Is it possible to change a section of URL text when using IMPORTXML to a reference cell

So I am trying to use IMPORTXML to pull data for stocks, but I want to simplify it with referencing a cell to change the stock name in the URL.
=IMPORTXML("https://www.marketwatch.com/investing/stock/aapl/financials/balance-sheet","/html/body/div[3]/div[6]/div/div[2]/div/div/table/tbody/tr[3]/td[2]/div/span")
So is there a way to make the "aapl" part of the URL reference to a cell that has a new stocks ticker to change the URL to a that new stocks balance sheet?
I am very new to this, sorry if my question doesn't make sense or is dumb. Thanks for any help provided.
Try this:
=IMPORTXML("https://www.marketwatch.com/investing/stock/"&A1&"/financials/balance-sheet","/html/body/div[3]/div[6]/div/div[2]/div/div/table/tbody/tr[3]/td[2]/div/span")
Change A1 with the cell you want

Can't display image in G sheets cell using Vlookup to get the link (returns blank or error)

I have a Google sheet with answers to a form, and I created a template in Google Sheets to transform each row in the answers sheet in a report, using vlookup (=PROCV in portuguese). The last column in the spreadsheet is a link for an image, uploaded by who answered the form.
The vlookup is working fine, except for the image. It's not displaying the image in the cell.
I have tried:
=image(PROCV(H7;'Respostas ao formulário 1'!1:630;21))
It returns a blank cell.
and also
=IMAGE("https://drive.google.com/uc?export=download&id="&INDEX(SPLIT(PROCV(H7;'Respostas ao formulário 1'!1:630;21),"="),1,2))
and
=IMAGE("https://drive.google.com/uc?export=download&id="&REGEXEXTRACT(PROCV(H7;'Respostas ao formulário 1'!1:630;21),"id\=(.+)"))
which I found here in stackoverflow, in another question about this issue, and return an "ERROR".
Also important, I've already changed permissions in the image (anyone with the link can access).
Any insights, please?
Thank you in advance for your time and attention.
If http://drive.google.com/uc?export=download&id={file_id} does not work, try this format:
Link Format:
http://drive.google.com/uc?export=view&id={file_id}
Try this publicly available image:
http://drive.google.com/uc?export=view&id=1YEpZitKgY6YT0TMDvOX4uqoxD5_aTuEv
Raw link image formula;
=image("https://drive.google.com/uc?export=view&id=1YEpZitKgY6YT0TMDvOX4uqoxD5_aTuEv")
Formula using regexextract to get file ID:
=Image("http://drive.google.com/uc?export=view&id="&REGEXEXTRACT(VLOOKUP(H7,'Respostas ao formulário 1'!1:630,21),"id\=(.+)"))
Outputs:
Vlookup output:
http://drive.google.com/uc?export=view&id=1YEpZitKgY6YT0TMDvOX4uqoxD5_aTuEv
Regexextract output:
1YEpZitKgY6YT0TMDvOX4uqoxD5_aTuEv
Raw link image output:
Image regexextract output:
Note:
If the image is still not showing, there is an issue with your link and it may not be available to anyone else. To confirm this issue, open the link in incognito mode. If it shows, it is publicly available. If not, then it isn't and the image will not show using IMAGE formula.
Make sure the one you append to the link format is only the ID and nothing else.
See sample sheet
EDIT:
It seems your lookup ID contains #, add a backslash before it by using the below formula
Formula:
=Image("http://drive.google.com/uc?export=view&id="&REGEXEXTRACT(VLOOKUP(regexreplace(H7; "#"; "\#");'Respostas ao formulário 1'!1:630;21);"id\=(.+)"))
Try setting the "is_sorted" parameter to false. From your first formula I gather you are looking up the value in H7 against the sheet 'Respostas ao formulário 1' rows 1 through 630 and you want the 23 column (W). Some areas that can give you problems is setting the sort to false, so it has to be an exact match, is the lookup value in the first column of the resource sheet?
Essentially with a format matching this you shouldn't have any issues:
Sheet named 'Respostas ao formulário 1'. Notice I have hidden columns B:V to consolidate the image and only show important information.
Finally the formula sheet:
We are looking up the value in cell F1 "Value1" against the second sheet and returning the image from the link.

Google Sheet how to determine if a cell has an image and if not insert my image

So i'm using importxml to get images from a website. Since image links in this website are truncated i'm successfully using this method:
In cell A1 i put main domain link : https://imagedomain.com/
In cell A2 i pull truncated image links with this formula:
=TRANSPOSE(query(importxml(B1 **(here image page link)** ;"
(/a/img/#src) |
(/a/img/#src) |
(/a/img/#src) ")))
(I import many images but in this example concentrating just in one cell and trucated links just show like text in cell similar to this: img/1234.jpg)
In cell A3 i united A1 and A2 with this formula:
=(A1)&(A2)
(This unites main domain with truncated image link and gives this: https://imagedomain.com/img/1234.jpg)
In cell A4 (last step) i show image with this formula:
=image(A3)
Now my problem is that sometime imported truncated link in A2 does not exist because that website offers no image but i still have a formula and link in A4. This is a problem because i can't use if blank to replace with one of my images.
My question is if there is any formula detecting if image shows and if not to insert my own image. I don't want to use any script.
I tried to explore if #alt because that website offers alt for every image but i don't know exactly how to do that. So my idea was if link + alt then verifies that there is image but if no alt then no image imported and then insert my image. This is just my idea how this could be solved ONLY with formula but maybe there are other and easier ways. Thnx
this may work:
=(A3<>"")*(NOT(ISTEXT(A3)))*(NOT(ISNUMBER(A3)))=1
but note that you would need to use all possible states to really make sure ...so:
=ISNONTEXT(A3)*
(NOT(ISBLANK(A3)))*
(NOT(ISNUMBER(A3*1)))*
(NOT(ISERROR(A3)))*
(NOT(ISTEXT(A3)))*
(NOT(ISFORMULA(A3)))=1
UPDATE:
try:
=INDEX(IF(COUNTIF(QUERY(LOWER(IMPORTXML($A$1; "//img/#alt"));
"where not Col1 matches '.*calendario.*|.*commenta.*'"; 0);
REGEXEXTRACT(LOWER(C3); "\d+ (.*) \("))*1=0;
IMAGE("https://i.imgur.com/RkXY3DB.jpg");
IMAGE("https://tv.zam.it/"&QUERY(QUERY({LOWER(
IMPORTXML($A$1; "//img/#alt"))\ IMPORTXML($A$1; "//img[#alt]/#src")};
"where not Col1 matches '.*calendario.*|.*commenta.*'"; 0);
"select Col2 where Col1 contains '"&
REGEXEXTRACT(LOWER(C3); "\d+ (.*) \(")&"'"; 0))))
spreadsheet demo
Try this... First check if your image returns text when using
=IMPORTDATA(A1)
If yes
Use this:
=IF(ISTEXT(IMPORTDATA(A1)),IMAGE(A1),"There is no Image there")
If no use this:
=IF(ISTEXT(IFERROR(IMPORTDATA(A1),FALSE)),IMAGE(A1),"There is no Image there")
A1 = is the Image URL (https://....jpg)

Google spreadsheet formula for url with a variable

What's the formula to display an url in google sheet when part of said url is a variable from another cell?
I'll explain: in one cell I have this formula (used to scrape text with class 'description' in an html webpage, doesn't matter for the purpose of the question though)
=importXML("http://www.xxx.it/code/9788823506183/doc/book.html","//span[#class='description']")
The numerical part changes everytime based on the value in another cell, say B3.
Tried =importXML("http://www.xxx.it/code/(B3)/doc/book.html","//span[#class='description']") but of course it won't work.
Then I thought I could dinamically create the url in B2 and do like this:
=importXML("B2","//span[#class='description']")
One step closer but I'm stuck anyway, how can I generate such url in B2? I can't find a suitable function in the docs. I could only come up with:
in A1 = 9788823506183
in B2 = http://www.xxx.it/code/("A1")/doc/book.html but it's not the correct syntax. :(
In Excel, you'd do something like the following. Give it a try in a google spreadsheet.
=importXML("http://www.xxx.it/code/" & B3 & "/doc/book.html","//span[#class='description']")
Use CONCAT in Google Sheets.
=CONCAT("http://www.xxx.it/code/(", $B2,")/doc/book.html")
You may need a formula to get the exact spot in the string.
The following example starts a timer based on a cell value but could be adapted to build a URL out of any cell values. Assume that there is a number of minutes that you want to make a timer for is in $C20
1) Make a cell that builds the first part of the URL, in my case $E27:
=CONCAT("https://www.google.com/search?q=set+timer+for+", $C20)
2) Make a second cell that completes the URL, in my case $E28:
=CONCAT($E27,"+minutes")
3) Make a cell that contains a hyperlink that will call up the timer:
=HYPERLINK($E28, "Start a timer for cell value C20")
Then when you click on the cell you made in #3 a hyperlink will hover over and you can click on it.

XPath function to combine text nodes and retrieve it to one Google Spreadsheet cell

I'm completely rookie in XPath (I don't even know how to paste proper html into this post ;-p) subject and I need some help. I would like to retrieve text which is in quotation marks and put it into a one cell in Google Spreadsheet. Right now I can only retrieve this text into separate cells.
http://imm.io/oLYI
Does string(//tr[class='darkGreen']/td[2]) result in what you want? Your XML fragment looks incomplete and I'm not sure if you only want the contents of the second cell so it's a wild guess if this fits your need.

Resources