View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_5_] Bob Phillips[_5_] is offline
external usenet poster
 
Posts: 620
Default using VBA to go back to the original value before the cell was changed

Mika,

Here you go

Dim myVar

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 Then
Application.EnableEvents = False
On Error GoTo ws_exit
If Target.Interior.ColorIndex = 10 Then
Target.Value = myVar
MsgBox "Change cancelled", vbInformation
End If
ws_exit:
Application.EnableEvents = True
End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
myVar = Target.Value
End Sub


--

HTH

Bob Phillips

"mika." wrote in message
...
I am trying to use VBA to do the following:

if there's a change to the worksheet,
if a cell is green
don't allow the change; go back to the original
value before the cell was changed.
else (cell is not green)
allo change

my problem is the "go back to the original value before
the cell was changed." any ideas how i might go about this?

i would just lock the fields and protect the sheet, but
the workbook is shared and i don't want to protect the
sheet in the shared workbook because then i can't insert
rows without unprotecting the workbook, etc.

thanks.