| How can I learn macros in Excel? | | | | Range("A2").Select |
| I have been asked this question many times by | | | | This code can be simplified, the underlying ideas being: |
| friends and colleagues. I don't think I have a perfect | | | | 1. There is no need to select the cell |
| answer for this, this is what I think. | | | | 2. There is redundant code that can be removed |
| Firstly, it is seldom good idea to pick up a book on | | | | The above code can be written into 2 lines: |
| Excel programming and start reading it from cover to | | | | Range("A1").Interior.ColorIndex = 6 |
| cover. I haven't seen this work so far, not only for | | | | Range("A1") = 34 |
| Excel VBA but for computer applications in general. | | | | The code is not only smaller but also more efficient: it |
| It is better to learn when there is a specific task at | | | | does only the required tasks and nothing more. |
| hand. Excel's macro recorder is a great way to begin: | | | | Learning to code this way takes some practice. |
| start the recorder, do the steps manually, and then | | | | Excel's VBA help is a great resource. To learn about |
| examine the code. | | | | the use of a specific keyword, type the word, place |
| The next step is to learn to modify and optimize the | | | | the cursor over it and press the F1 key. Sometimes it |
| code generated from the macro recorder. For | | | | helps to just look at the example in the help first |
| example, if the step needed is to change the | | | | than read the details. |
| background colour of the cell A1 to yellow and put in | | | | Once mastery of basic code is achieved, it is the |
| the number 34 into it, the macro recorder generates | | | | right time to pick up a book on VBA coding and |
| the following code: | | | | explore greater depths and possibilities. |
| Range("A1").Select | | | | VBA code is certainly not difficult to learn, but writing |
| With Selection.Interior | | | | efficient code takes some practice. Once you know |
| .ColorIndex = 6 | | | | VBA, it is fun too ! I have had great satisfaction |
| .Pattern = xlSolid | | | | playing with code and watching it do exactly what I |
| End With | | | | want as I sipped coffee! |
| ActiveCell.FormulaR1C1 = "34" | | | | |