VBA: 在用户定义的函数中创建单元格注释
VBA: Creating cell comment within user defined function
我有一个 UDF,它根据一堆输入变量进行计算。我试图让 UDF 创建一个单元格注释,其中包含有关这些变量的信息,但我只是得到 #VALUE!错误。
这就是我想要做的:
Function profit(income As Single, loss As Single) As Single
Dim cell As Range
cell = ActiveCell
profit = income - loss
call create_comment(cell, income, loss)
End function
呼叫子:
Private Sub create_comment(cell As Range, income As Single, loss As Single)
cell.ClearComments
cell.Addcomment "income =" & income & "loss =" & loss
End Sub
感谢所有帮助!
我把你的功能改成了那样
Function profit(income As Single, loss As Single, cell As Range) As Single
'Dim cell As Range
'cell = ActiveCell
profit = income - loss
Call create_comment(cell, income, loss)
End Function
然后你在函数的调用中进入活动单元格
=profit(1000,10,H10)
我有一个 UDF,它根据一堆输入变量进行计算。我试图让 UDF 创建一个单元格注释,其中包含有关这些变量的信息,但我只是得到 #VALUE!错误。
这就是我想要做的:
Function profit(income As Single, loss As Single) As Single
Dim cell As Range
cell = ActiveCell
profit = income - loss
call create_comment(cell, income, loss)
End function
呼叫子:
Private Sub create_comment(cell As Range, income As Single, loss As Single)
cell.ClearComments
cell.Addcomment "income =" & income & "loss =" & loss
End Sub
感谢所有帮助!
我把你的功能改成了那样
Function profit(income As Single, loss As Single, cell As Range) As Single
'Dim cell As Range
'cell = ActiveCell
profit = income - loss
Call create_comment(cell, income, loss)
End Function
然后你在函数的调用中进入活动单元格
=profit(1000,10,H10)