Jump to content
Fórum Script Brasil
  • 0

LOOP INFINITO


DANYY

Question

Boa tarde, estou criando uma macro para que ao ler a letra C nas celulas da coluna G, deve deslocar a celula ativa para direita pegar o valor de duas celulas a esquerda e transformar em valor negativo. Até ai esta funcionando corretamente, porem o loop esta infinito.. Segue o codigo:

Columns("G:G").Select

Do While ActiveCell.Offset(1, 0).Value <> ""


    Selection.Find(What:="C", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False).Activate

ActiveCell.Offset(0, 1).Select
    ActiveCell.FormulaR1C1 = "=+RC[-2]*-1"
    ActiveCell.Offset(0, -1).Select
Range(Selection, Selection.End(xlDown)).Select
   
Loop

Como proceder?

Edited by kuroi
Adicionar tag CODE
Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

danyy, tente assim:

Columns("G:G").Select

Dim ultimo As Range
Set ultimo = ActiveCell

Do While ActiveCell.Offset(1, 0).Value <> ""
    Set ultimo = Columns("G:G").Find(What:="C", After:=ultimo, LookIn:=xlFormulas, LookAt _
        :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
        False, SearchFormat:=False)
        
    If IsNull(ultimo) Then Exit Do
    
    ultimo.Activate

    ActiveCell.Offset(0, 1).Select
        ActiveCell.FormulaR1C1 = "=+RC[-2]*-1"
        ActiveCell.Offset(1, -1).Select
    Range(Selection, Selection.End(xlDown)).Select
Loop[/code]

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...