Change a Macro from Excel into Libre Calc

Dier Eluom
Dier Eluom used Ask the Experts™
on
Hi, I want to use this code in Libre Calc as a macro.  It is VB.  Is that possible?  How can I change it so that it works in Calc?

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
   


Dim rCell As Range
    Dim rChange As Range
   
    On Error GoTo ErrHandler
    Set rChange = Intersect(Target, Range("A:A"))
    If Not rChange Is Nothing Then
        Application.EnableEvents = False
        For Each rCell In rChange
            If rCell > "" Then
                With rCell.Offset(0, 1)
                    .Value = Now
                    .NumberFormat = "hh:mm:ss"
                End With
            Else
                rCell.Offset(0, 1).Clear
            End If
        Next
    End If

ExitHandler:
    Set rCell = Nothing
    Set rChange = Nothing
    Application.EnableEvents = True
    Exit Sub
ErrHandler:
    MsgBox Err.Description
    Resume ExitHandler
End Sub
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Serena HsiMarketing Consultant

Commented:
Here are some LibreCalc resources for creating macros:

LibreOffice Basic Programmer's Guide
https://ask.libreoffice.org/upfiles/13691375069537243.odt

LibreOffice Basic Macro Tutorial
http://www.debugpoint.com/libreoffice-basic-macro-tutorial-index/

Ten useful LibreOffice Macro Recipes (tutorial)
https://www.prahladyeri.com/blog/2016/02/ten-libreoffice-macro-recipes.html

Andrew Pitonyak's OpenOffice Macro Information (examples)
http://www.pitonyak.org/oo.php

Author

Commented:
I just found that code online.  I didn't write it.  However what it does is what I want a script to do in Libre Calc but I dont know how to write it.
Serena HsiMarketing Consultant

Commented:
You could record a macro in LibreCalc to see what the syntax is like, then adapt it for your needs.
I found a simple formula that solved the problem. = IF(A15="","",IF(B15="",NOW(),B15))

Author

Commented:
It works.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial