'But for' is a formal alternative to 'if it weren't for' or 'if it hadn't been for', commonly used in written English to express that one thing was essential for another outcome.
Quick tip: 'But for' + noun/gerund + would/would have. Always hypothetical - the thing mentioned prevented a negative outcome.
But for + noun (present/future)
Use But for + noun to mean 'if it weren't for'. Follow with would + infinitive for the result.
But for your help, I would be lost.
But for the traffic, we would arrive on time.
But for her support, he wouldn't succeed.
But for + noun (past)
Use But for + noun to mean 'if it hadn't been for'. Follow with would have + past participle.
But for your warning, I would have made a mistake.
But for the delay, we would have missed the accident.
But for her quick thinking, they would have failed.
But for + gerund
But for can also be followed by a gerund (verb + -ing) to express 'if it weren't for the fact that'.
But for having a map, we would have got lost.
But for knowing the password, I couldn't have accessed it.
But for speaking Spanish, she wouldn't have got the job.
Common mistakes
Not "But for your help, I will be lost." — say "But for your help, I would be lost.". Use 'would' not 'will' - this is hypothetical.
Not "But for you helped me, I would have failed." — say "But for your help, I would have failed.". 'But for' takes a noun or gerund, not a clause.
Not "But for the rain, we enjoyed the picnic." — say "But for the rain, we would have enjoyed the picnic.". Need 'would/would have' for the hypothetical result.
Practise it
Think of 'But for X' as 'X saved the situation'. But for your help = Your help saved me from being lost.