Search code examples
sortinggoogle-sheetsgoogle-sheets-formula

Sort Imported HTML Table in Google Sheets


I would like to sort THIS TABLE in a Google sheet after I import it using =IMPORTHTML("https://dividendhistory.org/monthly-payout/","table",1). It appears to sort momentarily when applied, but immediately reverts to the order supplied by the import.


Solution

  • The query function is probably your best option.

    For sorting on Col1 ascending use:

    =query(IMPORTHTML("https://dividendhistory.org/monthly-payout/","table",1),"select * order by Col1 ASC",1)
    

    For Col4 descending it changes to:

    =query(IMPORTHTML("https://dividendhistory.org/monthly-payout/","table",1),"select * order by Col4 DESC",1)
    

    Example spreadsheet