开发者

used a VBA object name as a variable

For a sloppy reason, I made a variable named 'cells' in my 开发者_开发知识库code like this

   Dim cells as Range

But now in all of my modules, the 'Cells' object has been replaced with the lowercase variable 'cells'. If I type in 'Cells', the VBA editor will automatically replace the text with 'cells'. Is there a way to fix this?


The only way to fix this is to rename cells to be Cells.


You could also just find and replace one at a time, it would be tedious though.


The bigger problem is that normally an unqualified use of Cells refers to the active sheet and thus returns a range (i.e. ActiveSheet.Cells) containing all of the cells on that active sheet (as long as the active sheet is a worksheet).

If your own variable called cells is in scope then it will take precedence over the global use of Cells. As both refer to a Range object there won't be any syntax errors - just difficult to find semantic ones.

I would rename the variable cells to something totally different instead. After that if Excel still changes Cells to cells then the suggestions in the link reafidy supplied above should help

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜