STRING MANIPULATION ! !

J

jay dean

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 ***
 
R

Rick Rothstein

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
 
J

Jacob Skaria

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
 
D

Dave Peterson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top