Vba what is the difference between select and activate




















For example, to enter a formula in cell D6 using Visual Basic, you do not need to select the range D6. Just return the Range object for that cell, and then set the Formula property to the formula you want, as shown in the following example.

For more information and examples of using other methods to control cells without selecting them, see How to: Reference Cells and Ranges. The Select method activates sheets and objects on sheets; 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. The macro recorder will often create a macro that uses the Select method and the Selection property. The following Sub procedure was created using the macro recorder, and it shows how Select and Selection work together. The following example performs the same task without activating or selecting the worksheet or cells.

If you use the Select method to select cells, be aware that Select works only on the active worksheet. Sheets "Sheet2". Activate Cannot activate different worksheets when several are selected The first line will select three worksheets and by default the first worksheet will be the active worksheet.

Sheets Array "Sheet1", "Sheet2", "Sheet3". Select The second line will not keep the current selection but will infact just select the "Sheet2" worksheet. Activate This is different functionality to the Select and Activate when using a Range object.

So you think you're executing in a one workbook when you're really referencing another. ThisWorkbook refers to the workbook containing the code being executed. Example It is very rare that you'll ever want to use Select or Activate in your code, but some Excel methods do require a worksheet or workbook to be activated before they'll work as expected.

Select Range "D3". Select ActiveCell. There are multiple issues with using. Select here: The worksheet is not always specified. This happens if you don't switch worksheets while recording, and means that the code will yield different results for different active worksheets. Select is slow.

Even if Application. ScreenUpdating is set to False , this is an unneccessary operation to be processed.



0コメント

  • 1000 / 1000