Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
GI GI is offline
external usenet poster
 
Posts: 1
Default Private Sub Worksheet_Change code not robust enough

I have a file with data in columns A, B and C. For each row, the data
in column B is dependent on the data in column A. Therefore, if
someone changes a cell in column A, or deletes the entry, I want the
entry in the same row of column B to be deleted. I have the code
below. It works when I hit Delete in column A, but when I hit
Backspace, it either jumps over to column C and deletes the entry
there, or jumps down 1 row and deletes the entry in column B. Thank
you for the assistance.

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column < 1 then
Exit Sub
End If

If Target.Column = 1
ActiveCell.Offset(0, 1).Select
Selection.ClearContent
End If

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Private Sub Worksheet_Change code not robust enough

Maybe...

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

if target.cells.count 1 then exit sub 'one cell at a time

If Target.Column < 1 then Exit Sub

'stop this procedure from calling itself
application.enableevents = false
target.offset(0,1).clearcontents
application.enableevents = true

End Sub

GI wrote:

I have a file with data in columns A, B and C. For each row, the data
in column B is dependent on the data in column A. Therefore, if
someone changes a cell in column A, or deletes the entry, I want the
entry in the same row of column B to be deleted. I have the code
below. It works when I hit Delete in column A, but when I hit
Backspace, it either jumps over to column C and deletes the entry
there, or jumps down 1 row and deletes the entry in column B. Thank
you for the assistance.

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column < 1 then
Exit Sub
End If

If Target.Column = 1
ActiveCell.Offset(0, 1).Select
Selection.ClearContent
End If

End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 897
Default Private Sub Worksheet_Change code not robust enough

Try this instead:

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column < 1 Then
Exit Sub
End If

If Target.Column = 1 Then
Application.EnableEvents = False
Target.Offset(0, 1).ClearContents
Application.EnableEvents = True
End If

End Sub


--JP

On Jul 31, 12:58*pm, GI wrote:
I have a file with data in columns A, B and C. *For each row, the data
in column B is dependent on the data in column A. *Therefore, if
someone changes a cell in column A, or deletes the entry, I want the
entry in the same row of column B to be deleted. I have the code
below. It works when I hit Delete in column A, but when I hit
Backspace, it either jumps over to column C and deletes the entry
there, or jumps down 1 row and deletes the entry in column B. *Thank
you for the assistance.

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column < 1 then
Exit Sub
End If

If Target.Column = 1
* * ActiveCell.Offset(0, 1).Select
* * Selection.ClearContent
* * End If

End Sub


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Private Sub Worksheet_change ... Procedures jamming up BEEJAY Excel Programming 5 October 25th 08 11:51 AM
Private Sub Worksheet_Change doesn't work? Sam Kuo[_3_] Excel Programming 2 March 9th 08 08:57 PM
Private Sub Worksheet_Change(ByVal Target As Range) pd1234321 Excel Programming 5 December 8th 06 04:11 AM
Private Sub Worksheet_Change(ByVal Target As Range) Arturo Excel Programming 1 May 25th 05 03:32 PM
Can someone help me make this code more robust? Henry Stock Excel Programming 1 February 23rd 05 05:26 PM


All times are GMT +1. The time now is 09:57 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"