Excel 中使用 VBA 的新函数

KunLun

首先,这是我第一次尝试vbaexcel. 我对此一无所知。

我尝试创建一个新函数 into excel,以在特定单元格中设置一个值。

我有这个模块:

Public Function SETVALUE(cell As Range, newValue As Integer) As String

    cell.value = newValue

    SETVALUE = "-"

End Function

这是我的模块:

如果我输入:=SETVALUE(A2, 1)in cell A1,它不起作用。

在单元格中A1出现#Value!,在单元格A2中什么也没有出现。

斯托拉克斯

试试这个

Option Explicit

Public Function SETVALUE(cell As Range, newValue As Integer) As String

    Evaluate "mySetValue( " & Chr(34) & cell.Address & Chr(34) & "," & Chr(34) & newValue & Chr(34) & ")"
    SETVALUE = "-"

End Function


Sub mySetValue(cell As String, newValue As Integer)
    Dim rg As Range
    Set rg = Range(cell)
    rg.Value2 = newValue
End Sub

更新:图片如何使用它

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章