0
votes

I'm looking for some assistance on how to retrieve a row number in Google Sheets that will work with the functions below.

I have put together (probably badly?) two instructions in Google Sheets that work together to pull the last section of a string in a variable string of data with an ARRAYFORMULA, REGEXREPLACE, REGEXEXTRACT in one cell that provides the data for an IFERROR, REGEXEXTRACT, CONCANTENATE in another cell.

These are intended to be inserted into a Google Sheet through an automation trigger (Zapier) and are designed to call and extract the tracking code for items from various platforms (eBay, Etsy, Woocommerce, direct entry, etc.) so the process needs to be dynamic.

I've been able to get the first set to work using the following as pasted into Google Sheets by Zapier.

=arrayformula(if(istext(P=P:ROW),{arrayformula(REGEXREPLACE(P=P:ROW,">.*","")),arrayformula(regexextract(P=P:ROW,"^.*>(.*)>.*$")),arrayformula(REGEXREPLACE(P=P:ROW,"^.*>",""))},))

This is able to call the ROW and update with each new line that is written in Google Sheets with each new Zap.

The challenge is getting the next step to work automatically where currently the formula is written with the cell numbers hardcoded in, as:

=IFERROR(REGEXEXTRACT(CONCATENATE(P2,IF(T2="","","/"),T2),"[^\/]+$"),"")

With this being written in the current format the automation process fails as each new line added to Google Sheets by Zapier instructs Google Sheets to look for data in row 2 (per the hardcoded 2).

This really needs to retrieve data in the 'same row' that it is written in.

A copy of the sheet can be found here: Google Sheets

  • Col P - Raw code fed from various ecommerce platforms
  • Col Q - First formula instruction pasted here by Zapier per the programmed Zap to create of a new line
  • Col R - Intentionally blank
  • Col S - Intentionally blank
  • Col T - Intentionally blank
  • Col U - Shipping Tracking Output pasted here by Zapier per the programmed Zap as a part of the same trigger to write to 'Col P' as above

If there is a better way to handle this I'd be happy to hear suggestions. I could use Java as a Zap to run the process if the code is capable of doing the same thing.

1
how to retrieve a row number in Google Sheets it's row()user13338210

1 Answers

0
votes

You can use Row() to get the row a formula is on, and INDEX to to reference a cell from a column. So change every instance of P2 to index(P:P,row())

Your formulas becomes

=arrayformula(if(istext(index(P:P,row())),{arrayformula(REGEXREPLACE(index(P:P,row()),">.*","")),arrayformula(regexextract(index(P:P,row()),"^.*>(.*)>.*$")),arrayformula(REGEXREPLACE(index(P:P,row()),"^.*>",""))},)) 

and

=IFERROR(REGEXEXTRACT(CONCATENATE(index(P:P,row()),IF(index(T:T,row())="","","/"),index(T:T,row())),"[^\/]+$"),"")