.Select, .Activesheet, .Activecell etc…

前端 未结 5 500
傲寒
傲寒 2021-01-13 04:40

For this question, I refer to the post below to clarify myself:
Why is my conditional format offset when added by VBA?

In many, many posts I see these days, OP\'

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-13 05:33

    I agree about Select and Activate, but not ActiveWorkbook, ActiveSheet, and ActiveCell (I agree that they are abused, but not that they should be avoided, per se). There are definitely legitimate uses for those. I have a program that automates a "fill series" that does so from the ActiveCell. My program can't predict what cells will be used; it's up the user to select it. That's part of the user interface.

    However, there are three situations where I have had to use Select (now four that I read about zoom, but I don't ever use it).

    1. Conditional Formatting. There is a work around using Application.ConvertFormula, but it's worse than just storing the selection, selecting the right cell, doing the deed, and reselecting the previous selection.
    2. Data Validation. Same reason.
    3. Shapes. I wish I could remember the details, but it's been too long since I've worked with Shapes. There was something I couldn't do without selecting the shape first.

    Ridding code of Select and Activate is a noble fight.

提交回复
热议问题