Vba Programming Basics

You can use comments for testing your code. If you have a line of code that is not functioning properly, you can comment it out and run your macro without it. This process eliminates the need to delete the line of code, and you can reactivate the commenting by simply removing the apostrophe at the beginning of the line. The following code comments the Selection.NumberFormat statement out so that the cell formatting remains unchanged when the macro runs.

Example:

Sub Sum_Values

ActiveCell.FormulaR1C1 =

1 =SUM(RC[-6]:RC[-1]) "

Range("B3:H3").Select

Range("H3").Activate

1 Selection.NumberFormat =

"$#,##0.00"

End Sub

□ Place the cursor at end of ° Type a description for the a variable declaration. selected variable.

Type an apostrophe ( ' ) at Q Type comments the beginning of the line. describing the selected procedure.

■ Start each comment line with an apostrophe.

□ Place the cursor at end of ° Type a description for the a variable declaration. selected variable.

■ When you run the selected procedure, VBA ignores the comment lines.

0 0

Post a comment