Link to home
Start Free TrialLog in
Avatar of ferguson_jerald
ferguson_jerald

asked on

How can I get this macro to work with libreoffice calc?

Hello Experts.

I have the following macro that works with Excel, but I would like to have a version that works with libreOffice as well.  I get an error with "dim r as Range" when I try to run it in libreOffice Calc.  It says "Basic syntax error.  Unknown data type Range".  Here's the macro:

Sub RemoveSelectColumns()
    Dim iColumn As Integer
    Dim strCell As String
    Dim strColumnName As String
    Dim r As Range
    
    iColumn = 1
    Do
        strCell = Cells(1, iColumn).Value
        If strCell = "" Then
            Exit Do
        End If
        If UCase(strCell) = "MOE" Then
            ' case-independent
            strColumnName = Split(Cells(1, iColumn).Address, "$")(1)
            Columns(strColumnName & ":" & strColumnName).Delete Shift:=xlToLeft
        Else
            iColumn = iColumn + 1
        End If
    Loop
End Sub

Open in new window


Any help would be greatly appreciated.
Avatar of ragnarok89
ragnarok89

I think you use

oSheets = ThisComponent.getSheets()
r
= oSheet.getCellRangeByName("A2:C5")

for example.
Avatar of TommySzalapski
Delete line 5. You never use r anyway.
ASKER CERTIFIED SOLUTION
Avatar of ltlbearand3
ltlbearand3
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial