ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   STRING MANIPULATION ! ! (https://www.excelbanter.com/excel-programming/427538-string-manipulation.html)

Jay Dean

STRING MANIPULATION ! !
 

Hello !

AA is a variable that contains a string. BB is another string variable.

I need a macro that will create a new string CC which is made by
inserting BB into AA (after the first word in AA).

Example: If AA="They are capable" and BB="think they", then CC should be
"They think they are capable." Any help would be apreciated!

Thanks
Jay


*** Sent via Developersdex http://www.developersdex.com ***

Rick Rothstein

STRING MANIPULATION ! !
 
You say you want a "macro", but the description of what you are looking for
is not a macro (another name for subroutine without arguments), so I'm not
totally sure how to answer your question. Here is code that will produce the
result you want in a variable named CC (we can dress it up as a function or
subroutine depending on what you might want, but you will have to clarify
that part for us)...

Dim AA As String, BB As String, CC As String
Dim Words() As String
AA = "They are capable"
BB = "think they"
Words = Split(AA)
Words(1) = Words(1) & " " & BB
CC = Join(Words)
MsgBox CC

--
Rick (MVP - Excel)


"jay dean" wrote in message
...

Hello !

AA is a variable that contains a string. BB is another string variable.

I need a macro that will create a new string CC which is made by
inserting BB into AA (after the first word in AA).

Example: If AA="They are capable" and BB="think they", then CC should be
"They think they are capable." Any help would be apreciated!

Thanks
Jay


*** Sent via Developersdex http://www.developersdex.com ***



Jacob Skaria

STRING MANIPULATION ! !
 
Just to add on if you are looking for formula..please try the below in C1
assuming

A1 = "They are capable"
B1 = "think they"

=SUBSTITUTE(A1," ", " " & B1 & " ",1)

If this post helps click Yes
---------------
Jacob Skaria


"jay dean" wrote:


Hello !

AA is a variable that contains a string. BB is another string variable.

I need a macro that will create a new string CC which is made by
inserting BB into AA (after the first word in AA).

Example: If AA="They are capable" and BB="think they", then CC should be
"They think they are capable." Any help would be apreciated!

Thanks
Jay


*** Sent via Developersdex http://www.developersdex.com ***


Dave Peterson

STRING MANIPULATION ! !
 
Another one:

Option Explicit
Sub testme()

Dim AA As String
Dim BB As String
Dim CC As String

AA = "They are capable"
BB = "think they"

If InStr(1, AA, " ", vbTextCompare) 0 Then
CC = Replace(AA, " ", " " & BB & " ", 1, 1, vbTextCompare)
End If

MsgBox CC

End Sub



jay dean wrote:

Hello !

AA is a variable that contains a string. BB is another string variable.

I need a macro that will create a new string CC which is made by
inserting BB into AA (after the first word in AA).

Example: If AA="They are capable" and BB="think they", then CC should be
"They think they are capable." Any help would be apreciated!

Thanks
Jay

*** Sent via Developersdex http://www.developersdex.com ***


--

Dave Peterson

Jay Dean

STRING MANIPULATION ! !
 

Thanks, Dave..I never knew the replace() function could take in 5
inputs.

Jay


*** Sent via Developersdex http://www.developersdex.com ***

Dave Peterson

STRING MANIPULATION ! !
 
VBA's help is nice <vbg.

jay dean wrote:

Thanks, Dave..I never knew the replace() function could take in 5
inputs.

Jay

*** Sent via Developersdex http://www.developersdex.com ***


--

Dave Peterson


All times are GMT +1. The time now is 03:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com