I’m trying to create a routine that replaces a variable number of values within a given string. For example, if I have a base text in the spreadsheet of:
“Your vehicle selection of {0} indicates you should have between {1} and {2} tires. However, you have entered {3} tires for this vehicle. Please update the record accordingly.”
I would like to replace the tokens with either a constant value from the application or some other variable a user entered. I’m trying to create a routine with a signature such as the following, where RowID is the row in the spreadsheet where the base text is located and ReplacementValues is an array of n number of variables:
Sub ShowMsg(ByVal RowID As Integer, Optional ByVal ReplacementValues As Variant)
I can’t figure out how to loop through the text and replace each token without repeating the entire text of the base message in each iteration. If possible I would like to keep the routine fairly generic and not specific to Excel in case I need to move the application to a database at some point later.
Hope I have explained this sufficiently; any help would be appreciated.
HTH