Vba recording a macro in Excel

There are numerous ocassions, when the programmer is stuck in the middle of the coding and not in position to obtain immediate help.

Even a well versed programmer may get struck at one point or the other.

For example, a programmer might want to do a filter along a column, but is not sure of how to get it done with right statements.

The excel offers an excellent help utility for this, "Macro Recording".

With this feature, one can simply set up excel to record further actions in a VBA macro and once done, it can be stopped and viewed to get the corresponding code.

This is a salient feature of Excel and is most helpful and first source of help acquired by any programmer.

For example, the following code is a recorded macro, which is obtained by activating various sheets in this workbook.

  1. Sub Recorded_Macro()
  2. ' Recorded_Macro Macro
  3. Sheets("Q40").Select
  4. Range("J4").Select
  5. ActiveWorkbook.Save
  6. Sheets("Q36").Select
  7. Rows("19:19").RowHeight = 16.5
  8. Sheets("Q35").Select
  9. Range("J19").Select
  10. Sheets("Q42").Select
  11. End Sub

The screenshot from the editor is as shown below:

excel vba recording a macro

Note that, this feature is simply used to get help on syntax and logic and cannot be used, at the least, in most cases, as a regular working macro.

Also, note that, the above code is not in a proper structure.It just records every user action in that order, rather a good program is well structured and\

readable, though, they both perform the same action.

The following screenshots demonstrates the macro recording:

excel vba recording a macro

excel vba recording a macro

excel vba recording a macro


You can find similar Excel Questions and Answer hereunder

1) I have a very complex macro that runs for a long time - is there any way I can set up an audible alarm indicating macro run is over?

2) How to enable or disable macros execution or loading in Excel

3) Converting numbers stored as text to numbers via macro in Excel

4) How to debug a macro in Excel VBA

5) How can I avoid updates to cell values during macro execution?

6) I frequently use a Macro - is there a way to quickly access the Macro using a Keyboard Shortcut?

7) How can I prevent users from seeing / accessing my macro code?

8) How can I execute an event at a predetermined time from my Macro?

9) I want to automatically run an initialization procedure whenever I open my WorkBook so that it is ready for use - how can I achieve that?

10) I frequently use a Macro - is there a way to quickly access the Macro in the Excel Ribbon?


Here the previous and next chapter