how to retrieve a cell value using LibreOffice Basic

I’m a newbie so please be kind. I simply want to bring the number in a cell (N3) of the current sheet into a macro for use in a select case routine. If I simply put iTT = 1,2 or 3 the macro works fine. When trying to look it up online, the only answers I can find are ones in which they are using ranges and for/next statements doing complicated stuff that I cannot understand. I’ve tried various ways with no success. The number in cell N3 is placed there by a list box selection.

Sub EnterTrans

Dim iTT As Integer
iTT = N3

Select Case iTT
    Case 1 
    	CashReceipts
    Case 2
    	Payroll
    Case 3 
    	Expenses
    Case Else
    Print "Hello nothing"
End Select

End Sub

1 Like

Hello,

Gain access to cell and retrieve value.

Sub EnterTrans
    Dim iTT As Integer
    Dim oActiveSheet As Object
    Dim oCellRangeByName As Object
Rem  Gets the Active sheet 
    oActiveSheet = ThisComponent.getCurrentController().getActiveSheet()
Rem Gets access to a cell
    oCellRangeByName = oActiveSheet.getCellRangeByName("N3")
Rem Get Value of cell
    iTT = oCellRangeByName.Value
    Select Case iTT
        Case 1 
            CashReceipts
        Case 2
            Payroll
        Case 3 
            Expenses
        Case Else
            Print "Hello nothing"
    End Select
End Sub

As with all questions, if this answers your question please tick the :heavy_check_mark: (upper left area of answer). It helps others to know there was an accepted answer.