The answer is similar to the answer: Copy and paste cell when changed
However, instead of copying and pasting, one should clean the cell.
Insert Event code
Use the event Worksheet_Change
, where the data shall be placed within the worksheet in which the data is located.
For example, in my case it was in Planilha1:
Code for a cell
The code is triggered every time the spreadsheet has some change in column H, where the cell in I is cleared with .ClearContents
Option Explicit
Private Const H As Long = 8 '<-- Coluna 8 ou H
Private Const I As Long = 9 '<-- Coluna 9 ou I
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo CleanExit
Application.EnableEvents = False
Dim coluna As Long '<-- Coluna selecionada
Dim linha As Long
coluna = Target.Column
linha = Target.Row
'Se ocorrer mudanças na coluna H
If coluna = H Then
Cells(linha, I).ClearContents
End If
CleanExit:
Application.EnableEvents = True
On Error GoTo 0
End Sub
Code for multiple cells
This code will perform the clean-up action next to the cell that was changed in column H.
Even if changes are made in multiple cells or if the interval is a non-contiguous cell range.
Option Explicit
Private Const H As Long = 8 '<-- Coluna 8 ou H
Private Const I As Long = 9 '<-- Coluna 9 ou I
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo CleanExit
Application.EnableEvents = False
Dim Coluna As Long '<-- Coluna selecionada
Dim linha As Long
Dim Area
Dim rng As Range
Coluna = Target.Column
'Caso mais de uma célula seja alterada
If Target.Count > 1 And Coluna = H Then
Set rng = Range(Target.Address)
For Each Area In rng.Areas
Area.Offset(, 1).ClearContents
Next
GoTo CleanExit
End If
'Se ocorrer mudanças na coluna H
If Coluna = H And Target.Count = 1 Then
linha = Target.Row
Cells(linha, I).ClearContents
End If
CleanExit:
Application.EnableEvents = True
On Error GoTo 0
End Sub
You want to select the H11 column and delete from I11 to I5000, or you want to click on the H12 row and delete i12?
– Heitor Scalabrini
I want to select the H12 column and delete i12
– Hugo Rutemberg
So what would replicate up to column 5000? [Edit] the question with more information.
– danieltakeshi
edited. can help ?
– Hugo Rutemberg
only one doubt, Oce already tried autofilter?
– Matheus Smark