Running VBA Code From Text in Excel

JoshuaKC29

New Member
Joined
Apr 20, 2019
Messages
10
Hello,

I'm not sure how to accurately provide a summary of what I'm trying to accomplish. I'm trying to create a user form that builds a "text template" based off of what a user inputs into the form. In short, the excel sheet would read:

"Testing One Two Three" & vbnewline & vbnewline & "Did This Work"

I want that text to be put into my macro. So strTextFormat = (above text)

Is this possible? Is there a way to accomplish this?
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Not sure if I can edit my original post. Couldn't see any sort of button to do so.

I ended up figuring out a solution to my problem. In short, this is what I've done:

Code:
Dim intCount As Integer         ''' Used to count how many cells have been used.
Dim strText As String           ''' Template for each cell.
Dim strVariable1 As String      ''' Variable to be replaced in cell.


Next_Transaction:               ''' If the user has multiple variables, loop and replicate formula using next variable.


intCount = intCount + 1         ''' Used to count how many cells have been used.


strText = TextBox1                          ''' Specified text of the user.
If TextBox2 <> "" Then
strText = strText & vbNewLine & TextBox2    ''' If user puts no information in second text box, then don't add new line.
End If


strVariable1 = Workbooks("Book1").Sheets("Sheet1").Cells(intCount, 3)       ''' This is the column contianing all the variables.


strText = Replace(strText, "<Variable 1>", strVariable1)                    ''' This is the string of text being added to column containing text format.


Workbooks("Book1").Sheets("Sheet1").Cells(intCount, 1) = strText            ''' This is the column the string of text is being added to.


If Workbooks("Book1").Sheets("Sheet1").Cells((intCount + 1), 3) <> "" Then  ''' This checks to see if additional variables were added. If so, repeat steps.
GoTo Next_Transaction
End If
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,693
Members
448,979
Latest member
DET4492

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