简体   繁体   English

在另一个工作表中调用范围(作为变量)

[英]Calling a Range (as a variable) in a different Worksheet

So, I have set a Range as a variable 所以,我已将Range设置为变量

Set Range_Count = Range("A2", Range("A2").End(xlDown))

And now I'm trying to call it in a WorksheetFunction using VBA without needing to select the worksheet 现在我试图在使用VBA的WorksheetFunction中调用它,而无需选择工作表

'This is what I don't want to do anymore
Sheets(1).Select
Count_Product = Application.WorksheetFunction.CountIf(Range_Count, "<>")

'This is what I'm wondering if it's possible to be done
Count_Product = Application.WokrsheetFunction.CountIf(Sheets(2).Range_Count, "<>")

But It doesn't seem to work. 但它似乎没有用。 Is there a way to do this? 有没有办法做到这一点?

This is how it works: 这是它的工作原理:

Set Range_Count = Sheets(2).Range("A2", Range("A2").End(xlDown)) 'full qualify the range with it's sheet
Count_Product = Application.WorksheetFunction.CountIf(Range_Count, "<>") 'then use the range

So, I just solved it by putting the sheets before Application like this 所以,我只是通过在Application之前放置这样的表来解决它

Dim Range_Count As Range
Set Range_Count = Range("A2", Range("A2").End(xlDown))

Sheets(2).Application.WorksheetFunction.CountIf(Range_Count, "<>")

Easier than I thought 比我想象的容易

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM