Grammar is the foundation of your writing. Just as a castle, a church or a house needs a solid foundation to support the rest of the structure, your writing needs the support and foundation of good grammar. Good grammar helps support your writing. Readers can more easily understand what you want to say if they are not distracted by grammatical errors.
For instance, do you know when you should write lay and when to write lie? Errors like writing "your" which infers ownership, "is that your new car?" when you want to say "you're" meaning "you are" as "you're the new class president," not only confuse the reader but send up red flags.
If you have a grammar question there are plenty of books out there ready to help you. One of the best is Strunk and White's classic THE ELEMENTS OF STYLE.
The Secret Way to Learn Good Grammar
There is a "secret" way to learn good grammar, though, without reading and studying a textbook. And that is by reading, reading, and reading some more.
Remember those authors you loved as a child? Read those stories again. Do you have children? What are they reading? Pick up their latest library book and read the story. Then go the extra mile and talk to them about the story.
But while you are reading, notice the writing. Why does your pre-teen love this book? What does your high school student like or dislike about the latest book their teacher assigned? Pay attention to the language and how it is put together.
The more you read, the more your writing will improve. Couple that with a bit grammar study and lots of practice writing. Remember, grammar is the foundation, the base of your castle. Your story builds the battlements, the jousting field, the courtyard and the banquet hall.
Your writing and your imagination are what will build what writers call the "story arc." Details of a story arc will be posted later.