Share via

Changing values in a custom class object within a dictionary

Anonymous
2021-02-17T16:21:53+00:00

Hello, I am trying to change the value of items within a custom class within excel. The custom class is stored in a Dictionary.

For example

Existing Dictionary:

Key Custom Class Item (cfield1, cfield2, cfield3)
a cfield1, cfield2, cfield3
b cfield1, cfield2, cfield3

If Key 'a', cfield2 has a value of "exist1, exist2", how do I later in the program change the key 'a' , cfield2 value to "new1, new2, new3"? I cannot simply create variables for 'exist' and change the values so I will actually need to modify the item value without changing the key. My current solution is to entirely replace the key/item pair for every entry requiring an edit.  Is there a way to directly change the value of a variable within a custom class while the class object is stored in a dictionary? Thanks in advance for any advice. 

Regards

pw

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2021-02-18T11:32:24+00:00

    I do not understand where your problem is, in a Dictionary you can store a new item using
      Dict.Item(Key) = Whatever
    but you have an object inside, so all you need to do is to refer to the object and change the values.

    Show me an example file if you need further help.

    Andreas.

    Was this answer helpful?

    0 comments No comments