J
Jim G
I have the following code used in data entry. I use it in several insatnces
and have no problems. However, in this configuration, it will, after 4 rows,
prompt for a response to the overwriting data test even though there is no
data in the target cells. I can skip a few lines and start re-entering and
after 4 lines it asks the over writie prompt again. In other workbooks
(different purpose/design) it will go forever if there is no data to over
write. The only thing I've added is "ActiveCell.Offset(0, 4).Value = "Y"" to
create a default, and changed the starting rows etc to fit the new form
demension. Anyone with any ideas?
Private Sub Worksheet_Change(ByVal target As Range)
If target.Cells.Count > 1 Then Exit Sub
If target.Column <> 6 Then Exit Sub 'last data entry cell
If target.Row < 19 Then Exit Sub 'starting row
If target.Offset(0, 1).Value <> "" Then
If MsgBox("You are overwrititng existing data. Are you sure?", vbYesNo) =
vbNo Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
Exit Sub
End If
End If
Application.EnableEvents = False
Cells(target.Row + 1, 1).Select
'MsgBox "Range" & target.Address & "was changed"
Range("g19:Q19").Copy target.Offset(0, 1).Resize(1, 8) 'formula row to copy
ActiveCell.Offset(0, 4).Value = "Y"
Application.EnableEvents = True
End Sub
and have no problems. However, in this configuration, it will, after 4 rows,
prompt for a response to the overwriting data test even though there is no
data in the target cells. I can skip a few lines and start re-entering and
after 4 lines it asks the over writie prompt again. In other workbooks
(different purpose/design) it will go forever if there is no data to over
write. The only thing I've added is "ActiveCell.Offset(0, 4).Value = "Y"" to
create a default, and changed the starting rows etc to fit the new form
demension. Anyone with any ideas?
Private Sub Worksheet_Change(ByVal target As Range)
If target.Cells.Count > 1 Then Exit Sub
If target.Column <> 6 Then Exit Sub 'last data entry cell
If target.Row < 19 Then Exit Sub 'starting row
If target.Offset(0, 1).Value <> "" Then
If MsgBox("You are overwrititng existing data. Are you sure?", vbYesNo) =
vbNo Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
Exit Sub
End If
End If
Application.EnableEvents = False
Cells(target.Row + 1, 1).Select
'MsgBox "Range" & target.Address & "was changed"
Range("g19:Q19").Copy target.Offset(0, 1).Resize(1, 8) 'formula row to copy
ActiveCell.Offset(0, 4).Value = "Y"
Application.EnableEvents = True
End Sub