Difference between Select and Activate

Texas Longhorn

Active Member
Joined
Sep 30, 2003
Messages
493
Hi all,

I'm a newbie to VBA, and I was hoping someone could explain to me the difference between Select and Activate. For example, all four of the following do the same thing:

Code:
Sub test()

Range("B2").Select
Range("B2").Copy Destination:=Selection.Offset(0, 1)

End Sub

Code:
Sub test()

Range("B2").Activate
Range("B2").Copy Destination:=ActiveCell.Offset(0, 1)

End Sub

Code:
Sub test()

Range("B2").Select
Range("B2").Copy Destination:=ActiveCell.Offset(0, 1)

End Sub

Code:
Sub test()

Range("B2").Activate
Range("B2").Copy Destination:=Selection.Offset(0, 1)

End Sub

Could someone please explain if there is any reason to use one or the other (or neither)?

Thanks,
Bill
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi Bill,

In all honesty, my advice would be to use neither, if you remove the line with the select or Activate on and run it you will see that it still does what you ask it without the inefficiency of having to Select/Activate the cell.
 
Upvote 0
Select can select multiple objects.

Activate can activate only one object.
Code:
Sub example()
Range("a1:a10").Select
MsgBox "Selection.Address = " & Selection.Address & vbLf & _
           "ActiveCell.Address = " & ActiveCell.Address
End Sub
 
Upvote 0
Thanks for the replies. Mikey B - I've read a few threads that also discuss omitting the Select or Activate to improve efficiency. My question then is what is the most efficient way to have the copied cell be pasted in a position relative to the copied cell? That is, if I don't select or activate in the first line then Selection.Offset(0,1) won't work. What would you recommend?

Thanks,
Bill
 
Upvote 0
If your code is not dependent on your user making their own selection and then executing your subroutine, you could use something like

Code:
With Range("B2")
    .Copy Destination:=.Offset(0, 1)
    ' Other stuff you want to do with Range("B2")
End With
 
Upvote 0
Code:
Sub test()
 
Range("B2").Activate
Range("B2").Copy Destination:=Selection.Offset(0, 1)
 
End Sub

Could someone please explain if there is any reason to use one or the other (or neither)?

Thanks,
Bill

You need to be very careful when using Activate on a range - it is better to use Select if you must actually select it. Try running the above in the following two situations and see what happens:
1. Select A1 then run the code.
2. Select a1:C10 then run the code.

Totally different scenarios!!
HTH
 
Upvote 0
gauntletxg - thanks for the tip; I have changed some code to mimic your example. rorya - thanks for the example. I tried it and completely see your point...a good demonstration.

Thanks,
Bill
 
Upvote 0

Forum statistics

Threads
1,223,671
Messages
6,173,737
Members
452,533
Latest member
Alex19k

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top