How to "kill" a class in VBA - Excel

0

I have a code that calls a Private sub which in turn erases the data from a worksheet. If I do the same procedure without closing the form it gives error at the time of erasing the data, however if I create a new sub with another name and the same code it normally runs twice. I wanted to know if there is any method like the dispose for objects in other languages, something that kills the sub after rolling everything inside it to be able to run again.

    
asked by anonymous 19.10.2018 / 19:07

1 answer

2

This is a code I just created for another user. Converting dates.

According to what I mentioned above, if I understood correctly you want the script to execute such a procedure, right? If positive try putting the command Exit Sub (without quotes) where you want to stop the code. Follow the template below.

Look for this note in the script below to better understand: <----- este é o código que faz parar o script.

DimCDataAsDateDimCData2AsDateSubDataCompra1(){'---FORMATANDODATAMOD01}[C8].SelectCData=[C8].ValueIfCData="0" Then
        MsgBox "INFORME A DATA"
        'Exit Sub '--- ESTA FUNÇÃO PARA O SCRIPT, CASO QUEIRA UTILIZAR DESCOMENTE A LINHA
    Else

        ActiveCell.Value = ""
        Selection.Offset(0, 2).Select
        ActiveCell.Value = CData
        Exit Sub                                 '<----- ESTE É O CÓDIGO QUE FAZ PARAR O SCRIPT.
        MsgBox CData

    End If

End Sub

Sub DataCompra2()
    {'--- FORMATANDO DATA MOD 02}

    Dim CData As Date
    Dim CHora As Date

    dt = [C8].Value
    CData = Format(dt)
    CHora = Format(Now)

    [E8].Value = CData
    [E9].Value = CHora

End Sub

Sub LimparData()

    [C8].Value = ""
    [E8].Value = ""

End Sub
    
19.10.2018 / 19:38