Forum Discussion
Zaac_Abrahams
Sep 21, 2020Copper Contributor
Function that automatically clears a cell once its numerical value is added to another cell.
Hi, This might be a silly question, but I was wondering if there was an Excel function that allows me to input a numerical value into one cell, have that value added to another cell, and then hav...
NikolinoDE
Sep 21, 2020Platinum Contributor
Here is a small approach if you want to do it with VBA under Excel 2016/2019, etc.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngc As Range, tmp As String
Application.EnableEvents = False
If Not Intersect(Target, Range("B2")) Is Nothing Then
Set rngc = Range("A:A").Find(What:=Target.Value, lookat:=xlWhole)
If Not rngc Is Nothing Then
tmp = Target.Value
Target.Clear
Rows(rngc.Row).Delete
'or if the found line should not be deleted: rngc.Clear
Else
MsgBox tmp & vbLf & "not in column A available!"
End If
End If
Application.EnableEvents = True
End Sub
Nikolino
I know I don't know anything (Socrates)
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngc As Range, tmp As String
Application.EnableEvents = False
If Not Intersect(Target, Range("B2")) Is Nothing Then
Set rngc = Range("A:A").Find(What:=Target.Value, lookat:=xlWhole)
If Not rngc Is Nothing Then
tmp = Target.Value
Target.Clear
Rows(rngc.Row).Delete
'or if the found line should not be deleted: rngc.Clear
Else
MsgBox tmp & vbLf & "not in column A available!"
End If
End If
Application.EnableEvents = True
End Sub
Nikolino
I know I don't know anything (Socrates)
Zaac_Abrahams
Sep 21, 2020Copper Contributor