Do not modify cell for a given result.( History)

Asked

Viewed 71 times

1

In a management table I have two columns a Status(Coluna A) and another Estado Anterior status. In this I want to keep the same value as in column A, except for some case. So that it keeps a status history when it is concluído

Ex.:

 Status                    Estado Anterior Status
 Em contato                Em contato

In case he doesn’t change

Status                    Estado Anterior Status
Concluído                 Em contato

Ps.: I have searched several code, but can’t execute it perfectly.

2 answers

1

Victor, with the code below the corresponding cell of column B will only receive the updated value of column A if it (column A) does not contain the word "Finished".

Dim i, Linha_inicial, Linha_final, Coluna As Integer 

Linha_inicial = 10 'Linha inicial dos dados a atualizar na Coluna B
Linha_final = 80 'Linha final dos dados a atualizar na Coluna B

Coluna = 1 '(valor para a Coluna A)

For i = Linha_inicial to Linha_final

 'Se a Coluna A não tem a palavra "Concluído"
 If Cells(i, Coluna) <> "Concluído" then

  'a linha i da Coluna B recebe o valor que está na coluna A                                                                        
  Cells(i, Coluna + 1) = Cells(i, Coluna)  'Coluna + 1 é a Coluna B (=2)

 End if

Next i 
  • 1

    This is @Leo. This answer helps me, but in the code above you scroll through the table to find a change. There’s a way I can do that every time I modify an A cell ?

  • A direct way to solve is to input by Vba through a field, which could be called from a Listbox to be similar to the spreadsheet, selecting the line would open a Textbox to enter the cell value. Then, it would remain to treat the result according to the entered value.

  • Another solution is to standardize the answers, by your example it seems that is the case, ai a Combobox resolve, p. Ex. "Open", "In progress", ..., "Completed

1


After clicking on the spreadsheet I was working on (at the bottom left corner) and selecting the option exibir código I put the following code

Private Sub Worksheet_Change(ByVal Target As Range)
    'Verifica se esta na coluna A'
     If Not Application.Intersect(Range("A:A"), Range(Target.Address)) Is Nothing Then
     'Verifica se é diferentes desses valores
        If Target.Text <> "Concluído" And Target.Text <> "Cancelado" And Target.Text <> "Pausado" Then
            Cells(ActiveCell.Row, "E") = Target
        End If
     End If
End Sub

Browser other questions tagged

You are not signed in. Login or sign up in order to post.