Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
J_J J_J is offline
external usenet poster
 
Posts: 58
Default 424 Object required error

Hi,
The below code manages to find if the inputted row is a duplicate of a
previous record and deletes it sucessfully but the VBA compiler gives an
error message as shown on the subject of this message...
Can someone correct the code?
'--------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 3 And Target.Column <= 5 Then ' 3 to 5 stand for C to E
columns

For i = 1 To Target.Row - 1

If (Cells(i, 3) = Cells(Target.Row, 3)) And (Cells(i, 4) =
Cells(Target.Row, 4)) And (Cells(i, 5) = Cells(Target.Row, 5)) Then
MsgBox "Duplicate record!"
Target.EntireRow.Delete
End If

Next

End If

End Sub

'--------------------
Thanks
J_J


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default 424 Object required error

should disable events to avoid recursion, and also break out of loop after
finding first duplicate
-Erik

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Column = 3 And Target.Column <= 5 Then ' 3 to 5 stand for C to E

For i = 1 To Target.Row - 1
If (Cells(i, 3) = Cells(Target.Row, 3)) And (Cells(i, 4) =
Cells(Target.Row, 4)) And (Cells(i, 5) = Cells(Target.Row, 5)) Then
MsgBox "Duplicate record!"
Target.EntireRow.Delete
Exit For
End If
Next

End If
Application.EnableEvents = True
End Sub

"J_J" wrote in message
...
Hi,
The below code manages to find if the inputted row is a duplicate of a
previous record and deletes it sucessfully but the VBA compiler gives an
error message as shown on the subject of this message...
Can someone correct the code?
'--------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 3 And Target.Column <= 5 Then ' 3 to 5 stand for C to
E
columns

For i = 1 To Target.Row - 1

If (Cells(i, 3) = Cells(Target.Row, 3)) And (Cells(i, 4) =
Cells(Target.Row, 4)) And (Cells(i, 5) = Cells(Target.Row, 5)) Then
MsgBox "Duplicate record!"
Target.EntireRow.Delete
End If

Next

End If

End Sub

'--------------------
Thanks
J_J




  #5   Report Post  
Posted to microsoft.public.excel.programming
J_J J_J is offline
external usenet poster
 
Posts: 58
Default 424 Object required error

Thank you E Overson,
Your suggestion cures the problem...
Regards
J_J

"E Oveson" wrote in message
...
should disable events to avoid recursion, and also break out of loop after
finding first duplicate
-Erik

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Target.Column = 3 And Target.Column <= 5 Then ' 3 to 5 stand for C to

E

For i = 1 To Target.Row - 1
If (Cells(i, 3) = Cells(Target.Row, 3)) And (Cells(i, 4) =
Cells(Target.Row, 4)) And (Cells(i, 5) = Cells(Target.Row, 5)) Then
MsgBox "Duplicate record!"
Target.EntireRow.Delete
Exit For
End If
Next

End If
Application.EnableEvents = True
End Sub

"J_J" wrote in message
...
Hi,
The below code manages to find if the inputted row is a duplicate of a
previous record and deletes it sucessfully but the VBA compiler gives an
error message as shown on the subject of this message...
Can someone correct the code?
'--------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 3 And Target.Column <= 5 Then ' 3 to 5 stand for C

to
E
columns

For i = 1 To Target.Row - 1

If (Cells(i, 3) = Cells(Target.Row, 3)) And (Cells(i, 4) =
Cells(Target.Row, 4)) And (Cells(i, 5) = Cells(Target.Row, 5)) Then
MsgBox "Duplicate record!"
Target.EntireRow.Delete
End If

Next

End If

End Sub

'--------------------
Thanks
J_J








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
Object Required Error Steph[_3_] Excel Programming 3 August 13th 04 03:26 PM
Object required - run time error 424. devorivivere Excel Programming 3 April 10th 04 05:43 PM
runtime error ....object required mlm Excel Programming 3 February 18th 04 06:09 PM
Syntax Error Runtime Error '424' Object Required sjenks183 Excel Programming 1 January 23rd 04 09:25 AM
error 424 - Object Required blb Excel Programming 0 October 1st 03 05:32 PM


All times are GMT +1. The time now is 11:19 AM.

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

About Us

"It's about Microsoft Excel"