Google Sheets – How to Insert Error or Spacer When IMPORTXML Fails

formulasgoogle sheetsimportxml

I am using IMPORTXML to create what is essentially a vehicle inventory feed file.

My issue arises when a price is not included in our main website. What seemingly is happening is when the price is not included the IMPORTXML is skipping that one, not including any error or anything, and including the next price that it finds in its place on the sheet.

This is an issue since we are trying to line up these trucks with their vin, msrp, price, etc.

https://docs.google.com/spreadsheets/d/1KceS3krlbpU2FjQly-tK8N5qiwshIq3rQFQ36WRNV5U/edit?usp=sharing

To give a specific example in my sheet this vin number: 1FTMF1E5XKKE62311 currently doesn't have a price listed on our site. Instead of inserting a blank cell or error, the IMPORTXML is inserting the price for the unit listed after this. This is creating a cluster of blank prices at the end of the sheet even though the prices for those vehicles are on our website. Basically this throws off the entire sheet after the first skipped price.

Here is how we are pulling in internet price currently:

=IFERROR({IMPORTXML(A4,"//div[@class='col-xs-12 visible-xs margin-top-1x']//span[@style='font-weight:bold;font-size:1.2em;'][@class='pull-right primaryPrice']");
 IMPORTXML(A5,"//div[@class='col-xs-12 visible-xs margin-top-1x']//span[@style='font-weight:bold;font-size:1.2em;'][@class='pull-right primaryPrice']");
 IMPORTXML(A6,"//div[@class='col-xs-12 visible-xs margin-top-1x']//span[@style='font-weight:bold;font-size:1.2em;'][@class='pull-right primaryPrice']");
 IMPORTXML(A7,"//div[@class='col-xs-12 visible-xs margin-top-1x']//span[@style='font-weight:bold;font-size:1.2em;'][@class='pull-right primaryPrice']");
 IMPORTXML(A8,"//div[@class='col-xs-12 visible-xs margin-top-1x']//span[@style='font-weight:bold;font-size:1.2em;'][@class='pull-right primaryPrice']");
 IMPORTXML(A9,"//div[@class='col-xs-12 visible-xs margin-top-1x']//span[@style='font-weight:bold;font-size:1.2em;'][@class='pull-right primaryPrice']");
 IMPORTXML(A10,"//div[@class='col-xs-12 visible-xs margin-top-1x']//span[@style='font-weight:bold;font-size:1.2em;'][@class='pull-right primaryPrice']");
 IMPORTXML(A11,"//div[@class='col-xs-12 visible-xs margin-top-1x']//span[@style='font-weight:bold;font-size:1.2em;'][@class='pull-right primaryPrice']")},"")

We were hoping that the error handler would work but unfortunately, it didn't. Does anyone have any thoughts on how we would not break the import order when there is a price that isn't listed?

Any advice would be much appreciated!!

update changed above sheet to be editable by anyone if you'd like to make a column and give it a shot

Best Answer

  • to avoid array literal errors it should be:

=QUERY({
 IFERROR(IMPORTXML(A4,  "//div[@class='col-xs-12 visible-xs margin-top-1x']//span[@style='font-weight:bold;font-size:1.2em;'][@class='pull-right primaryPrice']"), "");
 IFERROR(IMPORTXML(A5,  "//div[@class='col-xs-12 visible-xs margin-top-1x']//span[@style='font-weight:bold;font-size:1.2em;'][@class='pull-right primaryPrice']"), "");
 IFERROR(IMPORTXML(A6,  "//div[@class='col-xs-12 visible-xs margin-top-1x']//span[@style='font-weight:bold;font-size:1.2em;'][@class='pull-right primaryPrice']"), "");
 IFERROR(IMPORTXML(A7,  "//div[@class='col-xs-12 visible-xs margin-top-1x']//span[@style='font-weight:bold;font-size:1.2em;'][@class='pull-right primaryPrice']"), "");
 IFERROR(IMPORTXML(A8,  "//div[@class='col-xs-12 visible-xs margin-top-1x']//span[@style='font-weight:bold;font-size:1.2em;'][@class='pull-right primaryPrice']"), "");
 IFERROR(IMPORTXML(A9,  "//div[@class='col-xs-12 visible-xs margin-top-1x']//span[@style='font-weight:bold;font-size:1.2em;'][@class='pull-right primaryPrice']"), "");
 IFERROR(IMPORTXML(A10, "//div[@class='col-xs-12 visible-xs margin-top-1x']//span[@style='font-weight:bold;font-size:1.2em;'][@class='pull-right primaryPrice']"), "");
 IFERROR(IMPORTXML(A11, "//div[@class='col-xs-12 visible-xs margin-top-1x']//span[@style='font-weight:bold;font-size:1.2em;'][@class='pull-right primaryPrice']"), "")}, 
 "where Col1 is not null", 0)

Related Topic