I am building a User Defined Function.
I get an error
A Value used in the formula is of the wrong data type
I am trying to b
Assuming vesselCell
and shopCell
are both Range
objects, Range(vesselCell)
and Worksheets("Shop").Range(shopCell)
are part of the problem.
Make them Range
, not Variant
.
vesselCell.AddComment comment
shopCell.Value = comment
Now, this code isn't legal in a UDF. Make your procedure a Sub
procedure (remove the As Variant
return type), and invoke it from other VBA code, or attach it to a shape or button's OnAction
property.
User-Defined Functions take inputs, compute a result, and then return that result to the calling cell: your code not returning anything is a strong indicator that a Function
isn't appropriate here.