tt9527
Programmer
- May 10, 2008
- 2
Hi All,
I am new to VBA so my question can be really basic.
I need to create a user defined function in Excel that places a header in the cell above the function, if the cell above the function is empty. e.g. If you place =theFunction() is cell B1 and A1 is empty, it will write "The Function:" in A1 in addiction the result of theFunction in B1.
I wrote the following code:
Function AddOne(inValue As Integer)
AddOne = inValue + 1
Dim c As Comment
If IsObject(Application.Caller) = True Then
MsgBox Range(Application.Caller.Address).Offset(-1, 0).Address
c = Range(Application.Caller.Address).Offset(-1, 0).AddComment("Add One:")
Range(Application.Caller.Address).Offset(-1, 0).Value = "AddOne:"
End If
End Function
It returns "#value". I think the problem is with this but don't know how to fix it.
Range(Application.Caller.Address).Offset(-1, 0).Value = "AddOne:"
Can anyone shed some light? Thank you!
I am new to VBA so my question can be really basic.
I need to create a user defined function in Excel that places a header in the cell above the function, if the cell above the function is empty. e.g. If you place =theFunction() is cell B1 and A1 is empty, it will write "The Function:" in A1 in addiction the result of theFunction in B1.
I wrote the following code:
Function AddOne(inValue As Integer)
AddOne = inValue + 1
Dim c As Comment
If IsObject(Application.Caller) = True Then
MsgBox Range(Application.Caller.Address).Offset(-1, 0).Address
c = Range(Application.Caller.Address).Offset(-1, 0).AddComment("Add One:")
Range(Application.Caller.Address).Offset(-1, 0).Value = "AddOne:"
End If
End Function
It returns "#value". I think the problem is with this but don't know how to fix it.
Range(Application.Caller.Address).Offset(-1, 0).Value = "AddOne:"
Can anyone shed some light? Thank you!