Ask Your Question

find and replace macro [closed]

asked 2017-09-06 16:23:12 +0100

fbertoldi gravatar image

updated 2020-08-05 01:16:20 +0100

Alex Kemp gravatar image

How can I write a find and replace macro to merge many items in few, as "USA, Mexico, Canada, Honduras" in "America", "China, India, Vietnam" in "Asia" and so. Before macro: USA, Mexico, Canada, Honduras After macro: America, America, America, America


edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Alex Kemp
close date 2020-08-05 01:16:28.141469

1 Answer

Sort by » oldest newest most voted

answered 2017-09-06 16:59:45 +0100

JohnSUN gravatar image

updated 2017-09-06 17:00:13 +0100

It can be something like this:

Sub Geographer
Dim oDoc As Variant
Dim oSearchDescriptor As Variant
Dim oDictionary As Variant
Dim oReplace As Variant
Dim oStatusIndicator As Variant
Dim i As Long, j As Long 
    oDoc = ThisComponent
    oStatusIndicator = oDoc.getCurrentController().getStatusIndicator()
    oDictionary = Array( _
    Array("America",    "USA", "Mexico", "Canada", "Honduras"), _
    Array("Asia",       "China", "India", "Vietnam"), _
    Array("Europe",     "Ukraine", "Italy", "France", "Germany"), _
    Array("Africa",     "Qatar", "Tunisia") )
    oSearchDescriptor = oDoc.createSearchDescriptor()
    oStatusIndicator.start("", UBound(oDictionary)+1)
    For i = LBound(oDictionary) To UBound(oDictionary)
        oReplace = oDictionary(i)
        For j = 1 To UBound(oReplace)
        Next j
    Next i
End Sub
edit flag offensive delete link more


Thank you very much. I will try.

fbertoldi gravatar imagefbertoldi ( 2017-09-07 10:46:42 +0100 )edit

It works perfectly!!! Very good. Thank you!!

fbertoldi gravatar imagefbertoldi ( 2017-09-07 10:49:42 +0100 )edit

Question Tools

1 follower


Asked: 2017-09-06 16:23:12 +0100

Seen: 953 times

Last updated: Sep 06 '17