What is the difference between Sheets.Select and Sheets.Activate?

后端 未结 3 1713
野性不改
野性不改 2020-12-15 23:00

In VBA for Excel, what is the difference between Sheets.Select and Sheets.Activate ?

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 23:53

    To expand on the above: When the code below is run with Replace:=False no worksheet deactivation event occurs on sheet4. If Replace:=True is used instead then the de-activation event will fire.

    Preventing the event is desirable in most circumstances as it can cause unexpected behaviour.

    This means that select is only the equivalent of CTRL+Clicking a worksheet tab IF replace:=false is used.

    sub a

    Dim rng As Range
    
    Sheet4.Select Replace:=False
    Set rng = Selection
    
    Sheet5.Select Replace:=True
    Selection = rng.Value
    

    end sub

    Thanks for your posts as it helped me understand the difference.

    Harvey

提交回复
热议问题