Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7967841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:59:04+00:00 2026-06-04T06:59:04+00:00

I’m trying to create a routine that replaces a variable number of values within

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:59:05+00:00Added an answer on June 4, 2026 at 6:59 am

    You can;

    Sub ShowMsg(ByVal RowID As Integer, Optional ReplacementValues As Variant)
    Dim data As String, i As Long
    If Not IsMissing(ReplacementValues) Then
        data = Range("A" & RowID).Value
        For i = 0 To UBound(ReplacementValues)
            data = Replace(data, "{" & i & "}", ReplacementValues(i))
        Next
        msgbox data
    End If
    End Sub
    

    called with;

    Dim a() As Variant: a = Array("aa", "bb", "cc")
    ShowMsg 8, a
    

    Or an alternative:

    Sub ShowMsg(ByVal RowID As Integer, ParamArray ReplacementValues() As Variant)
    Dim data As String, i As Long
    If Not IsMissing(ReplacementValues) Then
        data = Range("A" & RowID).Value
        If IsArray(ReplacementValues(0)) Then ReplacementValues = ReplacementValues(0)
        For i = 0 To UBound(ReplacementValues)
            data = Replace(data, "{" & i & "}", ReplacementValues(i))
        Next
        msgbox data
    End If
    End Sub
    

    which can be called in the same way or additionally with ordinal arguments;

    ShowMsg 8, "aa", "bb", "cc"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a simple 3-D app for android that will have
I'm trying to create a routine in my asp.net's main page that will see
I'm trying to create a string from a regular expression. I noticed that in
i'm trying to create a bridge program in twisted.web that receives data from a
Im trying to pass the name of a global variable to a sub routine
I am trying to create a view in mySQL that gets created or updated
I am trying to write a generic data transformation routine that is table driven
I am trying to make a small thread example. I want to have a
I'm trying to create a button that performs some actions from my controller when
I am trying to create an app that allows the user to draw a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.