The macro recorder will often create a macro that uses the Select method and the Selection property but in Visual Basic, it is usually not necessary to select cells before modifying them.
Select works only on the active worksheet.
The Selection property returns an object that represents the current selection on the active sheet in the active workbook.
Before you can use the Selection property successfully, you must:
- activate a workbook,
- activate or select a sheet,
- and then select a range (or other object) using the Select method.
Macro Example with (Activation|Selection)
Sub Macro1() Sheets("Sheet1").Select Range("A1").Select ActiveCell.FormulaR1C1 = "Name" Range("B1").Select ActiveCell.FormulaR1C1 = "Address" Range("A1:B1").Select Selection.Font.Bold = True End Sub
Same Example without (Activation|Selection)
Sub Labels() With Worksheets("Sheet1") .Range("A1") = "Name" .Range("B1") = "Address" .Range("A1:B1").Font.Bold = True End With End Sub