Investing in haram stocks and donating revenue to charity

Assalamwalaikum,

This might be a weird one but I was wondering if I could invest in haram/questionable stocks with the intention of donating all revenue to charity?

I am currently holding shares in Microsoft and Berkshire Hathaway, one that is non compliant with Shariah Law and one that is questionable. I would like to hold these positions as they are expected to give a high return, and would like to donate all the money I make from them to charity.

Is this permissible as I am not benefitting from investing in these stocks, or should I just sell them and invest in something else?

Jazakhallah khair

Wa alaykum salaam,

This would not be permissible as it would be actively engaging in a transaction deemed impermissible, which is sinful. Further, you would be paying for something which the Shariah has not given value to, and you would be supporting the sales of such problematic assets.

Allah knows best