Libre Office Macro to find and move Cell Contents

I'm looking for a quick solution to create a macro in a LO Spreadsheet that will search a range of cells for a text string, then when finding one, move it into a second range of cells.

Here's what I have so far:
Sub ExtractByString()

Dim FindAddress As String
Dim extString As String, WCString
Dim oSheet
Dim oInCells, oOutCells
Dim Found

oSheet = ThisComponent.Sheets.getByName("Sheet1")
oInCells = oSheet.getCellRangeByName("A1:A50000")

extString = InputBox("Please Enter String.", "String Entry!")

WCString = oInCells.createSearchDescriptor
WCString.SearchString= "*" & extString & "*"
WCString.SearchSimilarity = True
WCString.SearchSimilarityAdd = 2
WCString.SearchSimilarityExchange = 2
WCString.SearchSimilarityRemove = 2
WCString.SearchSimilarityRelax = False


If "" = extString Then
    Exit Sub
Else
   Found = oInCells.FindFirst(WCString)

Endif 


End Sub

Open in new window


Now what I'm stuck on is I can't find any documentation on the properties/methods available to do what I want, particularly where the cell range that was found is returned so that I can move it to a different location.

Any thoughts appreciated....
Stan_GAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Stan_GAuthor Commented:
Got it figured, heres what I wound up doing....


REM  *****  BASIC  *****

Sub ExtractByString()

Dim Root As String, WCRoot
Dim oSheet
Dim oInCells, oOutCells, oCell
Dim Found

oSheet = ThisComponent.Sheets.getByName("Sheet1")
oInCells = oSheet.getCellRangeByName("A1:A50000")
oOutCells = oSheet.getCellRangeByName("I1:I50000")

oOutCells.clearcontents(23)



oRow = 0

oCell = oSheet.getCellByPosition(8, oRow)



Root = InputBox("Please Enter String.", "String Entry!")

WCRoot = oInCells.createSearchDescriptor
WCRoot.SearchString= Root
WCRoot.SearchSimilarity = False

If "" = Root Then
    Exit Sub
Else
   Found = oInCells.FindFirst(WCRoot)
   do while not isnull(Found)
   oCell = oSheet.getCellByPosition(8, oRow)
	oCell.setformula(Found.getFormula()
	oRow = oRow + 1
	Found.setformula("")
   Found = oInCells.FindFirst(WCRoot)
   loop
   
Endif 


End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Stan_GAuthor Commented:
After spending more time digging, finally found the info I needed.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
LibreOffice

From novice to tech pro — start learning today.