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

I received object required error on the following code:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range


Set rng = Range("$A$30:$A$10000")

With rng
DuplPack rng
End With
End Sub
------------------------------------------------------------------------------------------------
Sub DuplPack(rng As Range)

Dim Found As Range
Dim duplicates As Long
Dim a As Range
'On Error GoTo ErrHandler
If Intersect(Target, rng) Is Nothing Then Exit Sub 'This is the line
that gave me the error

Application.EnableEvents = False

duplicates = Application.CountIf(rng, Target.Value)

If Trim(Target.Value) < "" Then

If duplicates 1 Then

Set Found = rng.Find(Target.Value)

If Found.Address = Target.Address Then Set Found =
rng.FindNext(Target)

If Found.Address < Target.Address Then
MsgBox "The same Manufacturing Lot Number " & Target.Value &
" was found in cell" & Found.Address & " and cell " & Target.Address,
vbOKOnly, "Duplicate Manufacturing Lot Number"
Target.Activate
Target.ClearContents
End If

End If
End If

Set Found = Nothing
Set rng = Nothing

Application.EnableEvents = True
Exit Sub

'ErrHandler:

' MsgBox "An error occurred: " & CStr(Err.Number) & vbCrLf & _
' "Description: " & Err.Description & vbCrLf & vbCrLf & _
' "Copy or print error message and contact your system administrator."

End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Object required error

Target is not defined
--
Gary''s Student - gsnu200717


"anamarie30" wrote:

I received object required error on the following code:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range


Set rng = Range("$A$30:$A$10000")

With rng
DuplPack rng
End With
End Sub
------------------------------------------------------------------------------------------------
Sub DuplPack(rng As Range)

Dim Found As Range
Dim duplicates As Long
Dim a As Range
'On Error GoTo ErrHandler
If Intersect(Target, rng) Is Nothing Then Exit Sub 'This is the line
that gave me the error

Application.EnableEvents = False

duplicates = Application.CountIf(rng, Target.Value)

If Trim(Target.Value) < "" Then

If duplicates 1 Then

Set Found = rng.Find(Target.Value)

If Found.Address = Target.Address Then Set Found =
rng.FindNext(Target)

If Found.Address < Target.Address Then
MsgBox "The same Manufacturing Lot Number " & Target.Value &
" was found in cell" & Found.Address & " and cell " & Target.Address,
vbOKOnly, "Duplicate Manufacturing Lot Number"
Target.Activate
Target.ClearContents
End If

End If
End If

Set Found = Nothing
Set rng = Nothing

Application.EnableEvents = True
Exit Sub

'ErrHandler:

' MsgBox "An error occurred: " & CStr(Err.Number) & vbCrLf & _
' "Description: " & Err.Description & vbCrLf & vbCrLf & _
' "Copy or print error message and contact your system administrator."

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,101
Default Object required error

You need to give Target a Value I think

"anamarie30" wrote:

I received object required error on the following code:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range


Set rng = Range("$A$30:$A$10000")

With rng
DuplPack rng
End With
End Sub
------------------------------------------------------------------------------------------------
Sub DuplPack(rng As Range)

Dim Found As Range
Dim duplicates As Long
Dim a As Range
'On Error GoTo ErrHandler
If Intersect(Target, rng) Is Nothing Then Exit Sub 'This is the line
that gave me the error

Application.EnableEvents = False

duplicates = Application.CountIf(rng, Target.Value)

If Trim(Target.Value) < "" Then

If duplicates 1 Then

Set Found = rng.Find(Target.Value)

If Found.Address = Target.Address Then Set Found =
rng.FindNext(Target)

If Found.Address < Target.Address Then
MsgBox "The same Manufacturing Lot Number " & Target.Value &
" was found in cell" & Found.Address & " and cell " & Target.Address,
vbOKOnly, "Duplicate Manufacturing Lot Number"
Target.Activate
Target.ClearContents
End If

End If
End If

Set Found = Nothing
Set rng = Nothing

Application.EnableEvents = True
Exit Sub

'ErrHandler:

' MsgBox "An error occurred: " & CStr(Err.Number) & vbCrLf & _
' "Description: " & Err.Description & vbCrLf & vbCrLf & _
' "Copy or print error message and contact your system administrator."

End Sub


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

anamarie,

Your DuplPack subroutine will not recognize Target.

try changing the declaration to become

Sub DuplPack(rng As Range, Target as Range)

Then, call it as:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Set rng = Range("$A$30:$A$10000")
DuplPack rng, Target
End Sub




--
Hope that helps.

Vergel Adriano


"anamarie30" wrote:

I received object required error on the following code:

Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range


Set rng = Range("$A$30:$A$10000")

With rng
DuplPack rng
End With
End Sub
------------------------------------------------------------------------------------------------
Sub DuplPack(rng As Range)

Dim Found As Range
Dim duplicates As Long
Dim a As Range
'On Error GoTo ErrHandler
If Intersect(Target, rng) Is Nothing Then Exit Sub 'This is the line
that gave me the error

Application.EnableEvents = False

duplicates = Application.CountIf(rng, Target.Value)

If Trim(Target.Value) < "" Then

If duplicates 1 Then

Set Found = rng.Find(Target.Value)

If Found.Address = Target.Address Then Set Found =
rng.FindNext(Target)

If Found.Address < Target.Address Then
MsgBox "The same Manufacturing Lot Number " & Target.Value &
" was found in cell" & Found.Address & " and cell " & Target.Address,
vbOKOnly, "Duplicate Manufacturing Lot Number"
Target.Activate
Target.ClearContents
End If

End If
End If

Set Found = Nothing
Set rng = Nothing

Application.EnableEvents = True
Exit Sub

'ErrHandler:

' MsgBox "An error occurred: " & CStr(Err.Number) & vbCrLf & _
' "Description: " & Err.Description & vbCrLf & vbCrLf & _
' "Copy or print error message and contact your system administrator."

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
Object required error... IT_roofer Excel Programming 7 April 12th 07 06:36 PM
Object Required Error Marvin Excel Programming 5 March 20th 07 12:14 AM
Object Required error Patrick Simonds Excel Programming 3 August 26th 06 07:51 PM
Object Required Error Cody Excel Programming 14 August 23rd 05 12:31 AM
Syntax Error Runtime Error '424' Object Required sjenks183 Excel Programming 1 January 23rd 04 09:25 AM


All times are GMT +1. The time now is 05:33 AM.

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"