macro for deleting a particular string and inserting commas in it

P

Purple

Hi,
I need a MACRO FOR THIS URGENTLY
I have a long string namely: Yes TAX Invoicing No multi purpose Yes summer
time No tuna tub
The yes and No option varies from a row to row
i Want a Particular Output deleting ALL the NO's and the particular string
after no and all yes should appear in the row with proper commas
Desired OUTPUT:
TAX Invoicing, Summer time
 
J

Joel

mystr = "Yes TAX Invoicing No multi purpose Yes summer time No tuna tub"
myarray = Split(mystr, " ")
myoutput = myarray(1) & " " & myarray(2) & ", " & myarray(6) & " " &
myarray(7)
 
S

Sam Wilson

Function Splicer(myStr As String) As String

Dim aStr() As String
aStr = Split(myStr, " ")

Dim bInc As Boolean
bInc = True

Dim i As Integer
For i = 0 To UBound(aStr)

Select Case aStr(i)
Case "Yes"
bInc = True

Case "No"
bInc = False

Case Else
If bInc = True Then Splicer = Splicer & " " & aStr(i)

End Select

Next i

Splicer = Trim(Splicer)

End Function
 

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