Results 1 to 3 of 3

Thread: function that will set a specified cell to a specified value.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Newbie
    Joined
    Jun 2024
    Posts
    1
    Location

    function that will set a specified cell to a specified value.

    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
    Last edited by georgiboy; 06-06-2024 at 01:42 AM. Reason: Added code tags

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •