Replace cell value for particular String

headhair

New Member
Joined
Nov 8, 2010
Messages
15
I have to replace the cell values in a user form.

Cell A1 contains "Thomas"
Cell A2 contains "1000"

In a excel vba form, there are two textboxes
txtbox1 and txtbox2

I enter following text in txtbox1 :
Hello [A1], your outstanding is $[A2]
on exiting txtbox1,

I need code to display the txtbox2 with:
Hello Thomas, your outstanding is $1000

Thanks in advance
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi there,

Try:

Code:
txtbox2.value = "Hello " & Range("A1").value & ", your outstanding balance is $" & range("A2").value
 
Upvote 0
Mr. JamesW, thanks for reply.

txtbox1 is used for entering the template
The content may vary as per user.

I need a code for
whenever [A1] occurs in txtbox1, that should be replaced by content of cell "A1"
and similary for [A2] by content of cell "A2" programmatically and result
displayed in txtbox2.

Thanks again
 
Upvote 0
Hi there,

You mean that if the user manually types "[A1]" it will populate it with whatever is in A1, and if they were to type "[A6]" it will populate whatever is in A6?
 
Upvote 0
sorry for the late reply.

Thanks JamesW, you have understood my problem.

In the mean time I solved the problem myself
Code:
Private Sub txtbox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim txtMsg  As String
    For x = 1 To Len(txtbox1.Text) Step 1
        If Mid(txtTemplate.Text, x, 1) = "[" Then
            txtMsg = txtMsg & activesheet.range((Mid(txtbox1.Text, x + 1, 1) & "2"))
            x = x + 2
          Else
        txtMsg = txtMsg & Mid(txtbox1.Text, x, 1)
        End If
    Next
txtbox2.Value = txtMsg
End Sub

Thanks for your help.

The thread may be closed
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top