How to Write a Complicated Microsoft Office Macro

Write down the individual steps you want your macro to accomplish., Record several small macros., Open Visual Basic Editor., Combine the macros under one main macro using your written procedure as a guide., Modify the code to fit your procedure...

7 Steps 2 min read Medium

Step-by-Step Guide

  1. Step 1: Write down the individual steps you want your macro to accomplish.

    Write one step per line.

    Think like a computer.

    The macro is a set of commands telling your computer exactly what to do and gives all the information needed to do it.
  2. Step 2: Record several small macros.

    Each macro should perform a part of the task of your complete macro. , You will find the code for your recorded macros in several modules within either your current workbook or your Personal workbook. , Examine the code in each macro to understand what the code means, then copy and paste it into your main macro in the correct order that it needs to be executed. , The recorded macros may not fit exactly what you want to do.

    You may have to modify the code if you want to change the macro's behaviour. , If you just can't grasp what the code is meant to do, search online by copying the code into the search engine and adding key words like "excel"

    "macro" or "VBA". , While in Visual Basic Editor, you may press the F8 key to enter debugging mode and run your macro line by line.

    You may also create watches for each variable in your macro.

    Use these tools to see exactly what each line of code is doing.
  3. Step 3: Open Visual Basic Editor.

  4. Step 4: Combine the macros under one main macro using your written procedure as a guide.

  5. Step 5: Modify the code to fit your procedure.

  6. Step 6: Copy the code into a search engine.

  7. Step 7: Run the macro line by line.

Detailed Guide

Write one step per line.

Think like a computer.

The macro is a set of commands telling your computer exactly what to do and gives all the information needed to do it.

Each macro should perform a part of the task of your complete macro. , You will find the code for your recorded macros in several modules within either your current workbook or your Personal workbook. , Examine the code in each macro to understand what the code means, then copy and paste it into your main macro in the correct order that it needs to be executed. , The recorded macros may not fit exactly what you want to do.

You may have to modify the code if you want to change the macro's behaviour. , If you just can't grasp what the code is meant to do, search online by copying the code into the search engine and adding key words like "excel"

"macro" or "VBA". , While in Visual Basic Editor, you may press the F8 key to enter debugging mode and run your macro line by line.

You may also create watches for each variable in your macro.

Use these tools to see exactly what each line of code is doing.

About the Author

B

Benjamin Simmons

Brings years of experience writing about cooking and related subjects.

58 articles
View all articles

Rate This Guide

--
Loading...
5
0
4
0
3
0
2
0
1
0

How helpful was this guide? Click to rate: