A 1031 exchange rolls the gain from the sale of your old property into your new one. Both properties have to have been held for investment, or used in a trade or business, and you only have 180 days from the sale of your old property to get your new property purchased.
The problem is that Section 1031 says that it does not apply to "property held primarily for sale." So how does the IRS know if your intent was to hold it for investment, which would qualify for a 1031 Exchange, or hold it for sale, which would not? The IRS will look at a number of factors:
Why you originally bought the property
What you subsequently did with it
The extent of the improvements you made to it
The number and frequency of other transactions you've done;
The business you are in
The effort you went to find a buyer for your property
The listing of the property for sale with real estate brokers
What you were doing with the property at the time you sold it.
In other words, if you make your living by buying fixers, or building spec houses, and you always sell your properties within a few months of the completion of the construction or renovation, and especially if the income would be "ordinary income" to you (as opposed to short term capital gains), you have almost no hope of your 1031 Exchange passing IRS scrutiny in the event of an audit. On the other hand, if you always hold your properties for a considerable length of time, and this one time the buyer came to you and made an unsolicited offer you could not refuse, you could justify a 1031 exchange transaction.