Monthly Archives: December 2013

OpenOffice Calc macro: search a cell

Sub Find
    sAns = InputBox("Enter what to find below.")
    If sAns = "" then End 'Blank entry or Cancel clicked.
    oDoc = ThisComponent
    oCell = oDoc.CurrentSelection 'Get active sheet index.
    index = oCell.CellAddress.Sheet
    oSheet = oDoc.getSheets.getByIndex(Index)'Get active sheet.

    FandR = oSheet.createSearchDescriptor 'Set up find and replace.
    FandR.setSearchString(sAns)
    'FandR.SearchWords = true 'Entire cell must match.
    oCell = oSheet.findFirst(FandR)
    If isNull(oCell) then
    endif

    MsgBox "Row = " & oCell.CellAddress.Row & Chr(13) & "Column = " &
    oCell.CellAddress.Column
    Else MsgBox "Not Found!"
    EndIf
End Sub

Reference:

Return column and row using Calc search in a macro