ryaeger
06-06-2024, 01:01 AM
Please help me.
I am trying to write a function that will set a specified cell to a specified value. (Code is below).
Let's say my current location is A1. In A1, I enter =SetCellValue(M2, "Bob") expecting M2 to be set to "Bob".
Instead A1 is set to #VALUE!.
Same with =SetCellValue("M2", "Bob"). Debugging shows that the problem occurs at the TargetCell.Value = NewValue
Debugging also shows that TargetCell and NewValue are being passed to my function. Everything is in the same Sheet.
I have made this as simple as I could. but I can't figure out what I am doing wrong.
Function SetCellValue(TargetCell As Range, NewValue As Variant)
' Set the value of the target cell
TargetCell.Value = NewValue
End Function
I am trying to write a function that will set a specified cell to a specified value. (Code is below).
Let's say my current location is A1. In A1, I enter =SetCellValue(M2, "Bob") expecting M2 to be set to "Bob".
Instead A1 is set to #VALUE!.
Same with =SetCellValue("M2", "Bob"). Debugging shows that the problem occurs at the TargetCell.Value = NewValue
Debugging also shows that TargetCell and NewValue are being passed to my function. Everything is in the same Sheet.
I have made this as simple as I could. but I can't figure out what I am doing wrong.
Function SetCellValue(TargetCell As Range, NewValue As Variant)
' Set the value of the target cell
TargetCell.Value = NewValue
End Function