• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

On Error Doubt

Hi!

I´d like to right a code that when error ocuors then it should jump a part of the code and read another (On error GoTo), but when error doesn't ocuors then it shouldn't read that part of error treatment.

Code:
For i = 2 To uLinha
 
On Error GoTo adicionar
 
    procurar = WorksheetFunction.Match(Sheets("Termos").Cells(i, 7), intervalo, 0)
    Sheets("MtM").Cells(7, procurar) = Sheets("Termos").Cells(i, 20)
    Sheets("MtM").Cells(5, procurar) = Sheets("Termos").Cells(i, 21)
   
adicionar:
   
    cliente = Sheets("Termos").Cells(i, 5)
    contrato = Sheets("Termos").Cells(i, 7)
    ativo = Sheets("Termos").Cells(i, 15)
    prazo = Sheets("Termos").Cells(i, 4)
    dias = Sheets("Termos").Cells(i, 21)
   
    Sheets("MtM").Cells(1, fimCol + 1) = cliente
    Sheets("MtM").Cells(2, fimCol + 1) = contrato
    Sheets("MtM").Cells(3, fimCol + 1) = ativo
    Sheets("MtM").Cells(4, fimCol + 1) = prazo
    Sheets("MtM").Cells(5, fimCol + 1) = dias
   
    fimCol = fimCol + 1
   
Next

In this case, if error ocuors then go to "adicionar", if not then jump the "adicionar" part.

Thanks!
 
Like this?

Code:
For i = 2 To uLinha
 
On Error GoTo adicionar
 
    procurar = WorksheetFunction.Match(Sheets("Termos").Cells(i, 7), intervalo, 0)
    Sheets("MtM").Cells(7, procurar) = Sheets("Termos").Cells(i, 20)
    Sheets("MtM").Cells(5, procurar) = Sheets("Termos").Cells(i, 21)
   GoTo JumpMe
adicionar:
   
    cliente = Sheets("Termos").Cells(i, 5)
    contrato = Sheets("Termos").Cells(i, 7)
    ativo = Sheets("Termos").Cells(i, 15)
    prazo = Sheets("Termos").Cells(i, 4)
    dias = Sheets("Termos").Cells(i, 21)
   JumpMe:
    Sheets("MtM").Cells(1, fimCol + 1) = cliente
    Sheets("MtM").Cells(2, fimCol + 1) = contrato
    Sheets("MtM").Cells(3, fimCol + 1) = ativo
    Sheets("MtM").Cells(4, fimCol + 1) = prazo
    Sheets("MtM").Cells(5, fimCol + 1) = dias
   
    fimCol = fimCol + 1
   
Next
 
thanks! But I dont know the On Error GoTo is not working... there still a message of error number 1004 when the match function don't work...
 
Code:
For i = 2 To uLinha
 
On Error GoTo adicionar
 
    procurar = WorksheetFunction.Match(Sheets("Termos").Cells(i, 7), intervalo, 0)
    Sheets("MtM").Cells(7, procurar) = Sheets("Termos").Cells(i, 20)
    Sheets("MtM").Cells(5, procurar) = Sheets("Termos").Cells(i, 21)
    Err.Clear:On Error GoTo 0:On Error GoTo -1
   GoTo JumpMe
adicionar:
   Err.Clear:On Error GoTo 0:On Error GoTo -1
    cliente = Sheets("Termos").Cells(i, 5)
    contrato = Sheets("Termos").Cells(i, 7)
    ativo = Sheets("Termos").Cells(i, 15)
    prazo = Sheets("Termos").Cells(i, 4)
    dias = Sheets("Termos").Cells(i, 21)
   JumpMe:
    Sheets("MtM").Cells(1, fimCol + 1) = cliente
    Sheets("MtM").Cells(2, fimCol + 1) = contrato
    Sheets("MtM").Cells(3, fimCol + 1) = ativo
    Sheets("MtM").Cells(4, fimCol + 1) = prazo
    Sheets("MtM").Cells(5, fimCol + 1) = dias
   
    fimCol = fimCol + 1
   
Next
 
Back
Top