Text in Textbox to be added to stored code on command button

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,731
Office Version
  1. 2007
Platform
  1. Windows
Morning,
On my command button I’m looking for it to copy a Textbox value on my userform & insert it into the stored code of which is then placed into another textbox.

Example,
Textbox1 has the value NEW

The command button will have a default string of HAPPY?YEAR

Basically the ? Is where the textbox value should be placed.
The code will then be placed into Textbox2

I plan to use this code on other command buttons BUT some will have characters as the stored code.

Example of stored code.
ABC@&?

Textbox4 has the value Z46

So the text Z46 is added to the stored code so when placed in the Textbox it will be ABC@&Z46
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Maybe something like this?
VBA Code:
Private Sub CommandButton1_Click()
  TextBox2.Text = Replace(CommandButton1.Caption, "?", TextBox1.Text)
End Sub
 
Upvote 0
I dont understand your code.

See here
Rich (BB code):
Private Sub CommandButton6_Click()
TextBox3.TEXT = Replace(CommandButton6.Caption, "EMERGENCY", TextBox1.TEXT)
End Sub

The value in TextBox1 is 999

So the value put in TextBox3 isnt 999EMERGENCY but the name of the command button which is CommandButton6
 
Upvote 0
No

TextBox1 has a value of say MERRY

On the command button code is aspecial word so in this example its CHRISTMAS

So when the user clicks on the command button it needs to Copy TextBox1 value & add to special word CHRISTMAS

Then past in TextBox3 so MERRY CHRISTMAS

Like i mentioned some times special work could be (abc123,,
 
Upvote 0
VBA Code:
Private Sub CommandButton1_Click()
  Dim specialWord As String
  specialWord = "HAPPY ? YEAR"
  TextBox2.Text = Replace(specialWord, "?", TextBox1.Text)
End Sub

1702638749156.png
1702638764138.png
 
Upvote 0
Then your special word must be like:
VBA Code:
Private Sub CommandButton1_Click()
  Dim specialWord As String
  specialWord = "? HAPPY YEAR"
  TextBox2.Text = Replace(specialWord, "?", TextBox1.Text)
End Sub

It replaces question mark as you have mantioned in your original post.
 
Upvote 0
Here is the code im trying as i have to experiment

Rich (BB code):
Private Sub CommandButton6_Click()
  Dim specialWord As String
  specialWord = "MsgBox ("?"),"
  TextBox3.TEXT = Replace(specialWord, "?", TextBox1.TEXT)
End Sub

The code in Red in where i mention about characters

Special word is MsgBox ("?"),

TextBox1 value is THIS IS THE MESSAGE

This becomes MsgBox ("THIS IS THE MESSAGE"),
 
Upvote 0
VBA Code:
Private Sub CommandButton1_Click()
  Dim specialWord As String
  specialWord = "MsgBox (""?""),"
  TextBox2.Text = Replace(specialWord, "?", TextBox1.Text)
End Sub

1702640130194.png
1702640149753.png
 
Upvote 0
Solution

Forum statistics

Threads
1,223,885
Messages
6,175,179
Members
452,615
Latest member
bogeys2birdies

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