Olá
Pretendia que a macro abaixo fosse executa automaticamente, sempre que o valor de J11, da folha “registo” seja alterado. O valor de J11 é igual a : =J9&J10. Pelo que entendi uma possibilidade seria nos Eventos, Conteúdo alterado. Mas não estou a ser capaz de executar esse passo. Alguém me poderia indicar os passos ou uma outra solução? ( como a macro tem 300 e tal linhas, indico só as partes principais, eliminando parte do conteúdo central da mesma que é sempre igual, alterando apenas os valores. )
Obrigado
Sub CopiarColarSe
Dim oDoc As Object
Dim oRegisto As Object
Dim oTabelas As Object
Dim i As Integer
Dim oRange As Object
oDoc = ThisComponent
oRegisto = oDoc.Sheets.getByName("registo")
oTabelas = oDoc.Sheets.getByName("tabelas")
' Verificar se o valor de "J11" corresponde a um dos casos especificados
Select Case oRegisto.getCellRangeByName("J11").String
    Case "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "210", "211", "212", "213", "214", "215", "216", "217", "218", "219", "220", "221", "222", "310", "311", "312", "314", "315", "316", "317", "321", "322", "410", "411", "412", "414", "415", "416", "417", "421", "422", "514", "515", "522"
        ' Continuar com a execução da macro
    Case Else
        MsgBox "COMBINAÇÃO INEXISTENTE", vbExclamation
        Exit Sub ' Interromper a execução da macro
End Select
' Limpar o conteúdo das células A14 a F100 na folha "registo"
oRange = oRegisto.getCellRangeByName("A14:F100")
oRange.clearContents(1023)
Select Case oRegisto.getCellRangeByName("J11").String
    Case "110"
        For i = 0 To 28
            oRegisto.getCellByPosition(1, 13 + i).String = oTabelas.getCellByPosition(0, 2 + i).String
            oRegisto.getCellByPosition(0, 13 + i).String = oTabelas.getCellByPosition(1, 2 + i).String
        Next i
    Case "111"
        For i = 0 To 30
            oRegisto.getCellByPosition(1, 13 + i).String = oTabelas.getCellByPosition(2, 2 + i).String
            oRegisto.getCellByPosition(0, 13 + i).String = oTabelas.getCellByPosition(3, 2 + i).String ' Copiar D3:D33 da folha "tabelas" e colar na folha "registo" a partir de A14
        Next i
    Case "112"
        For i = 0 To 27
            oRegisto.getCellByPosition(1, 13 + i).String = oTabelas.getCellByPosition(4, 2 + i).String
            oRegisto.getCellByPosition(0, 13 + i).String = oTabelas.getCellByPosition(5, 2 + i).String ' Copiar F3:F30 da folha "tabelas" e colar na folha "registo" a partir de A14
etc…etc…etc…
       Next i
End Select
' Centralizar o conteúdo das células A14 a A100 na folha "registo"
oRegisto.getCellRangeByName("A14:A100").HoriJustify = com.sun.star.table.CellHoriJustify.CENTER
' Alinhar à esquerda o conteúdo das células B14 a B50 e C14 a C50 na folha "registo"
oRegisto.getCellRangeByName("B14:B50").HoriJustify = com.sun.star.table.CellHoriJustify.LEFT
oRegisto.getCellRangeByName("C14:C50").HoriJustify = com.sun.star.table.CellHoriJustify.LEFT
End Sub
