首先,这是我第一次尝试vba
在excel
. 我对此一无所知。
我尝试创建一个新函数 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] 删除。
我来说两句