When one should use Set [e.g for SpecialCells return value]?

后端 未结 4 1281
逝去的感伤
逝去的感伤 2020-11-27 23:39

I am afraid I misunderstand the documentation of VBA for excel, I have this line which seems to be an error:

Range a = Selection.SpecialCells(xlCellTypeConst         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-28 00:29

    enter image description here

    Range.SpecialCells Method returns a Range object that represents all the cells that match the specified type and value. set keyworkd is used to assign a reference to an object.

    There are two flavors of assignments in VBA: one for ordinary variables, which use Let, and one for object variables, which use Set.

    An ordinary (string, logical, numeric) variable is one that points to the location in memory where the variable is stored.

    An object variable (all the things you find in the language reference under Objects) is one that points to a structure in memory (a VTable) that in turn contains pointers to the object's properties and methods.

    Reference http://www.excelforum.com/excel-programming-vba-macros/693357-when-to-use-the-keyword-set.html

提交回复
热议问题