gpt4 book ai didi

vba - 替代命令 (ActiveSheet)

转载 作者:行者123 更新时间:2023-12-03 00:19:24 24 4
gpt4 key购买 nike

有用户定义函数(UDF),位于工作簿的所有工作表上。

如何引用该函数所在的工作表?

我正在使用ThisWorkbook.ActiveSheet,但结果不断变化。

Function äëÿñèò(Diapozon As Range) As Long
'äëÿ ñèòóàöèè
Application.Volatile
Dim n As Long
Dim C As Range
Dim m As Long

m = -1
n = 0
For Each C In Diapozon.Rows

If C.Value = 1 Then
m = m + 1
If ThisWorkbook.ActiveSheet.Cells(101, 42 + (m * 21)).Value = 1 Then
n = n + 1
End If
End If
Next C

äëÿñèò = n
End Function

最佳答案

您可以使用 Application.Caller 来引用正在调用该函数的单元格,因此您可以使用 Application.Caller.Worksheet 来引用该单元格的工作表。

关于vba - 替代命令 (ActiveSheet),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47937745/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com