Hi everyone,
I've written a little code in vba but since I'm totally new to vba, it doesn't really do yet what i want.
The code is meant to track changes in a document that is used over different companies. (I know there are better options like office online but this is impossible for several reasons). Now, when someone changes a cell I want to make sure they give a reasoning for their change or otherwise they can't go on.
The problem with this code is that when I double click a cell and don't change anything, the code still asks for a reasoning. Which I would like to avoid.
Here's what I've got already:
My first idea was to read in the entire range in a variable or table or something (before any edits are made) and then compare the new value of the cell with the old one that is stored. But it seems to me that there should be easier solutions...
Does anyone have an idea?
Thank you!
I've written a little code in vba but since I'm totally new to vba, it doesn't really do yet what i want.
The code is meant to track changes in a document that is used over different companies. (I know there are better options like office online but this is impossible for several reasons). Now, when someone changes a cell I want to make sure they give a reasoning for their change or otherwise they can't go on.
The problem with this code is that when I double click a cell and don't change anything, the code still asks for a reasoning. Which I would like to avoid.
Here's what I've got already:
Code:
Private Sub Worksheet_Change(ByVal Target As Range) Dim KeyCells As Range
Dim rng As Range
Dim MyInput As Variant
Dim CellContent As Variant
Set KeyCells = Range("D4:D35")
If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing Then
'ask for reasoning and put it in the comment of the cell.
MyInput = InputBox("Give a reasoning please.")
Set rng = Range(Target.Address)
With rng.AddComment
.Visible = False
.Text MyInput
While MyInput = ""
MyInput = InputBox("Give a reasoning please.")
Wend
End With
'Highlight changed cell
Target.Interior.ColorIndex = 6
End If
End Sub
My first idea was to read in the entire range in a variable or table or something (before any edits are made) and then compare the new value of the cell with the old one that is stored. But it seems to me that there should be easier solutions...
Does anyone have an idea?
Thank you!