Monday, February 14, 2011

Some more tips for beginning macro recorders:

The apostrophe is used do indicate a comment. Anything after the apostrophe is ignored by VBA

This is object oriented programming. The basic syntax is object.action. If a object oriented compiler were playing soccer, it would say "ball.kick" in order to kick the ball. So "Selection.Cut" says to do an "edit > cut" on the current selection.

The Range modifiers are relative to the active cell. If the active cell is in B2 and you say "ActiveCell.Range("A1:C3").Select", then you select the 3 row by 3 column area starting in cell B2. In other words, you select B2:D4. Saying "ActiveCell.Range("A1")" says to select the 1 x 1 cell range starting with the active cell. This is incredibly redundant. It is equivalent to saying "ActiveCell.Select".

Save your workbook before running a macro for the first time. This way, if it has an error and does something unexpected, you can close without saving and revert back to the saved version.

++++++++++++++++++
Sub Macro1()

Do Until ActiveCell.Value = ""

Loop
End Sub

No comments:

Post a Comment