[英]Calling a Range (as a variable) in a different Worksheet
所以,我已將Range設置為變量
Set Range_Count = Range("A2", Range("A2").End(xlDown))
現在我試圖在使用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, "<>")
但它似乎沒有用。 有沒有辦法做到這一點?
這是它的工作原理:
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
所以,我只是通過在Application
之前放置這樣的表來解決它
Dim Range_Count As Range
Set Range_Count = Range("A2", Range("A2").End(xlDown))
Sheets(2).Application.WorksheetFunction.CountIf(Range_Count, "<>")
比我想象的容易
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.