Escolar Documentos
Profissional Documentos
Cultura Documentos
com
With Relative Recording turned off, the resulting macro will always select J11. With Relative Recording turned on, the resulting macro will go down one cell from the current cell. Do you see how much more useful this macro is? The rst macro only works when you happen to be in J10. The second macro works anywhere except row 1048576. Turn Use Relative References on every day. (It resets back to off when you close Excel). This one is so important, it is shown twice, once in 2010 and once in 2013.
Unfortunately, Ctrl+Period wont correctly record jump to next corner of selection number.
Allow Macros
By default, macros will not run in Excel. Use the Macro Security icon in the Developer tab. Choose the second option, which is Disable All Macros With Notication. This sounds like this wont allow macros, right? It gives you a visible warning when you open a workbook that contains macros. You get to choose if you Enable macros or not. If it is a le that you wrote, you can Enable. If it is a le from an unknown hacker, you can leave them disabled.
Other useful navigation that will be recorded correctly by the macro recorder: Ctrl+Home to return to A1. Ctrl+* to select current region. Ctrl+End to move to the last cell (although the macro version has the same problems as the Excel version) Ctrl+PgDn to move to next worksheet to the right. Ctrl+PgUp to move to previous worksheet.
in the status bar in the lower left corner of your Excel screen. Anything you do will get recorded in the macro. If your manager walks in and asks you to open a report and print it, this will get recorded in your macro. When you are done with the steps, dont forget to click Stop Recording.
Else Cells(i, 5).Font.Color = RGB(12,12,12) End if If you have to check for many different possible conditions, use Select Case ' Status Code is in column J Select Case Cells(i, j) Case "A", "B", "E" ' Do Something Case "C" 'Something else Case "D", "G" 'Something Else Case Else MsgBox Error in row " & i End Select
FormulaR1C1
The macro recorder does formulas in R1C1 style. You can switch .FormulaR1C1 to .Formula, or you can learn the cool R1C1 style: =RC refers to the cell that holds the formula. =RC[-3] refers to current row, 3 columns to the left of the formula. =R[1]C refers to current column, 1 row down. =R1C refers to row $1 of the current column =RC1 refers to column $A of the current row =R1C13 refers to $M$13
Misc. Tips
Avoid Excel asking questions: Application.DisplayAlerts = False Worksheets("Sheet2").Delete Application.DisplayAlerts = True For faster macros, use Application.ScreenUpdating = False If an error is possible and OK, skip the error message. In the following example, you are trying to delete a text le. If the le is missing, Excel will stop and tell you that it can not nd the le to delete it. That means the le has already been deleted and there is no reason to stop the macro.: On Error Resume Next Kill ("C:\aaa\FileLog.txt") On Error GoTo 0
Moving to VBA
There are several things the macro recorder will never do. Your strategy can be to rely on the macro recorder for 90% of your macro, and then add these items in the VBA window.
MrExcel.com
2014 MrExcel.com