Hi, am needing some help with e VB code.
I have a spreadsheet and I am wanting to have a cell add its value into another cell to increase the value in said cell.
If the number ‘2’ is input into D6 and down to D200 etc… I want this to add to the value of E6 and the cell next to the D Cell. So E6 would change from ‘10’ to ‘12’ for example.
This will also pop up with a custom message saying ‘yes’ or ‘no’ and then the value in D6 would be removed automatically.
I am also wanting to the same for G6 having its value added into F6 increasing the value again.
Attached in my test spreadsheet image and below is the VB script I have at the moment but it is only deducting the value away and I can’t get it to do addition. Also is there anything else I should change in the code to make it work for all cells?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("H6")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
'MsgBox "Cell " & Target.Address & " has changed."
If Trim(Range("H6").Value) <> "" Then
MSG1 = MsgBox("Deduct Quantity?", vbYesNo)
If MSG1 = vbYes Then
Range("F6").Value = Range("B2").Value - Range("F6").Value
Range("H6").Value = ""
Else
Range("H6").Value = ""
End If
End If
End If
End Sub
Thanks for the help.
Screen Shot 2016-11-10 at 10.28.01.png
Bookmarks