View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
astridc astridc is offline
external usenet poster
 
Posts: 3
Default find wildcard text between {} cut, and paste in another cell

Hello Jacob,
thank you! when I try this macro however, it will only extract the "{" and
the first word of the comment, but the comments between {} have various
lenghts.


"Jacob Skaria" a scris:

The below macro should do this.

If you are new to macros --Set the Security level to low/medium in
(Tools|Macro|Security). 'Launch VBE using short-key Alt+F11. Insert a module
and paste the below code. Save. Get back to Workbook. Tools|Macro|Run Macro1()


Sub Macro1()

Dim intRow, strTemp, strData, arrData
intRow = 1

Do While Trim(Range("A" & intRow)) < ""
strData = Trim(Trim(Range("A" & intRow)))

Do
strTemp = strData
strData = Replace(strData, "{ ", "{")
strData = Replace(strData, " }", "}")
If strTemp = strData Then Exit Do
Loop

arrData = Split(strData, " ")
strTemp = ""
strData = ""
For intTemp = 0 To UBound(arrData)
If Left(arrData(intTemp), "1") = "{" Then
strData = strData & arrData(intTemp) & vbLf
Else
strTemp = strTemp & arrData(intTemp) & " "
End If
Next

Range("B" & intRow) = Trim(strTemp)
Range("C" & intRow) = Trim(strData)

intRow = intRow + 1
Loop

End Sub

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