Investors & landlords

I have very similar situation as @xzll, except the lease ended 6/30/2019 with tenants moved out 3rd week of June.  The property was left beat and gross so we planned to take 2 months to gut it.  In August, I posted the property for rent on Zillow.  I got nervous to get the right people in there that would take care of the place (after I sank 40K in renovation)  so we listed the property for sale in early September with a realtor.   The market went really cool and so I listed it for rent simultaneously.  In the end, we sold it to Zillow and chose a closing date just after the new year of 2020.   Basically the property was never occupied or put in use in the second half of 2019.

My question is, can I still do what @Carl  suggested to avoid the recaptured depreciation in TY2020?   Or must I file away the 40K of renovation as capital improvement for 2019?  If the later, would I be able to add most of that 40K investment back as cost basis to offset the capital gain realized at time of sales of the property in Jan 2020?   Thank you.