Can someone please tell me if my dividend gains can be offset with losses on sale of a stock in tax loss harvesting?

eg. I received dividends of $2000 in 2023... and a loss on one of the stock sale (long-term) of $4000.

Can I offset that $2000 dividend gain, and another $2000 in loss (the limit for tax-loss harvesting being $3000), and thus not paying any tax on the dividends?

Thank you.