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

Guys, I try to use function to solve my problem but I keep getting
"Object required' error. Could you help me to fix this problem?
Thank you for all your help.

Private Sub CommandButton1_Click()

Dim shtJ As Worksheet
Dim shtK As Worksheet
Dim shtL As Worksheet
Dim rngC As Range
Dim rngE As Range
Dim rngJ As Range
Dim rngK As Range
Dim rngL As Range
Dim Cell As Range
Dim rw As Long

Set shtJ = Worksheets("Labour A")
Set shtK = Worksheets("Labour B")
Set shtL = Worksheets("Labour C")


Set rngC = Range(Cells(16, 3), Cells(Rows.Count, 3))
Set rngJ = shtJ.Range(shtJ.Cells(6, 5), shtJ.Cells(86, 5))
Set rngK = shtK.Range(shtK.Cells(6, 4), shtK.Cells(86, 4))
Set rngL = shtL.Range(shtL.Cells(6, 5), shtL.Cells(86, 5))
rw = 16
rngC.Clear

For Each Cell In rngJ
Call mylabour
Next Cell

For Each Cell In rngK
Call mylabour
Next Cell

For Each Cell In rngL
Call mylabour
Next Cell

End Sub

Function mylabour(rngJ, rngK, rngL As Range) As Range

If Cell < "xxx" Then
With Cell
If Application.CountIf(rngC, .Value) = 0 Then
Cells(rw, 3).Value = .Value
rw = rw + 1
End If

End With
End If

End Function

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

rngC, Cell and rw is declared in the calling sub, and is not passed as an
argument to the Function, which means that when you try and use it in the
Function, it will implicitly create a new object, that will be Nothing, so
the COUNTIF fails.

Also, your function has loads of arguments it doesn't use, lose them.

Add Option Explicit at the head of your code, it won't allow implicit
creation of variables, you have to explicitly declare them, avoiding these
pitfalls.

Apart from that, what is the Function supposed to do. The use of cell and
the range is confusing me.



--

HTH

RP
(remove nothere from the email address if mailing direct)


"broogle" wrote in message
oups.com...
Guys, I try to use function to solve my problem but I keep getting
"Object required' error. Could you help me to fix this problem?
Thank you for all your help.

Private Sub CommandButton1_Click()

Dim shtJ As Worksheet
Dim shtK As Worksheet
Dim shtL As Worksheet
Dim rngC As Range
Dim rngE As Range
Dim rngJ As Range
Dim rngK As Range
Dim rngL As Range
Dim Cell As Range
Dim rw As Long

Set shtJ = Worksheets("Labour A")
Set shtK = Worksheets("Labour B")
Set shtL = Worksheets("Labour C")


Set rngC = Range(Cells(16, 3), Cells(Rows.Count, 3))
Set rngJ = shtJ.Range(shtJ.Cells(6, 5), shtJ.Cells(86, 5))
Set rngK = shtK.Range(shtK.Cells(6, 4), shtK.Cells(86, 4))
Set rngL = shtL.Range(shtL.Cells(6, 5), shtL.Cells(86, 5))
rw = 16
rngC.Clear

For Each Cell In rngJ
Call mylabour
Next Cell

For Each Cell In rngK
Call mylabour
Next Cell

For Each Cell In rngL
Call mylabour
Next Cell

End Sub

Function mylabour(rngJ, rngK, rngL As Range) As Range

If Cell < "xxx" Then
With Cell
If Application.CountIf(rngC, .Value) = 0 Then
Cells(rw, 3).Value = .Value
rw = rw + 1
End If

End With
End If

End Function



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

From what I can see,
It is collecting a list of unique entries. It doesn't appear to have
arguments that aren't used as designed although some could be eliminated
(such as rw) but then additional code might be needed.

See my suggested rewrite.

--
Regards,
Tom Ogilvy


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


"Tom Ogilvy" wrote in message
...

It doesn't appear to have arguments that aren't used as designed ....


rngJ, rngK, rngL? Where are they used in the function?


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

For Each Cell In rngJ
Call mylabour
Next Cell

For Each Cell In rngK
Call mylabour
Next Cell

For Each Cell In rngL

--
Regards,
Tom Ogilvy


"Bob Phillips" wrote in message
...

"Tom Ogilvy" wrote in message
...

It doesn't appear to have arguments that aren't used as designed ....


rngJ, rngK, rngL? Where are they used in the function?






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

But that is in the commandbutton sub, not the function, hence my point.

Bob


"Tom Ogilvy" wrote in message
...
For Each Cell In rngJ
Call mylabour
Next Cell

For Each Cell In rngK
Call mylabour
Next Cell

For Each Cell In rngL

--
Regards,
Tom Ogilvy


"Bob Phillips" wrote in message
...

"Tom Ogilvy" wrote in message
...

It doesn't appear to have arguments that aren't used as designed ....


rngJ, rngK, rngL? Where are they used in the function?






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

Thanks Tom, It works!!!
And also thank to everyone who tried to help me. Happy Easter !

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

Private Sub CommandButton1_Click()

Dim shtJ As Worksheet
Dim shtK As Worksheet
Dim shtL As Worksheet
Dim rngC As Range
Dim rngE As Range
Dim rngJ As Range
Dim rngK As Range
Dim rngL As Range
Dim Cell As Range
Dim rw As Long

Set shtJ = Worksheets("Labour A")
Set shtK = Worksheets("Labour B")
Set shtL = Worksheets("Labour C")


Set rngC = Range(Cells(16, 3), Cells(Rows.Count, 3))
Set rngJ = shtJ.Range(shtJ.Cells(6, 5), shtJ.Cells(86, 5))
Set rngK = shtK.Range(shtK.Cells(6, 4), shtK.Cells(86, 4))
Set rngL = shtL.Range(shtL.Cells(6, 5), shtL.Cells(86, 5))
rw = 16
rngC.Clear

For Each Cell In rngJ
Call mylabour(cell, rw, rngC)
Next Cell

For Each Cell In rngK
Call mylabour(cell, rw, rngC)
Next Cell

For Each Cell In rngL
Call mylabour(cell, rw, rngC)
Next Cell

End Sub

Function mylabour(cell As Range, rw as Long, rngC as Range)
If Cell < "xxx" Then
With Cell
If Application.CountIf(rngC, .Value) = 0 Then
Cells(rw, 3).Value = .Value
' a value was added, so increase or adjust size of
' rngC
Set rngC = Range(Cells(16, 3), Cells(Rows.Count, 3))
rw = rw + 1
End If

End With
End If
End Function

--
Regards,
Tom Ogilvy


"broogle" wrote in message
oups.com...
Guys, I try to use function to solve my problem but I keep getting
"Object required' error. Could you help me to fix this problem?
Thank you for all your help.

Private Sub CommandButton1_Click()

Dim shtJ As Worksheet
Dim shtK As Worksheet
Dim shtL As Worksheet
Dim rngC As Range
Dim rngE As Range
Dim rngJ As Range
Dim rngK As Range
Dim rngL As Range
Dim Cell As Range
Dim rw As Long

Set shtJ = Worksheets("Labour A")
Set shtK = Worksheets("Labour B")
Set shtL = Worksheets("Labour C")


Set rngC = Range(Cells(16, 3), Cells(Rows.Count, 3))
Set rngJ = shtJ.Range(shtJ.Cells(6, 5), shtJ.Cells(86, 5))
Set rngK = shtK.Range(shtK.Cells(6, 4), shtK.Cells(86, 4))
Set rngL = shtL.Range(shtL.Cells(6, 5), shtL.Cells(86, 5))
rw = 16
rngC.Clear

For Each Cell In rngJ
Call mylabour( cell, rw)
Next Cell

For Each Cell In rngK
Call mylabour cell, rw
Next Cell

For Each Cell In rngL
Call mylabour cell, rw
Next Cell

End Sub

Function mylabour(rngJ, rngK, rngL As Range) As Range

If Cell < "xxx" Then
With Cell
If Application.CountIf(rngC, .Value) = 0 Then
Cells(rw, 3).Value = .Value
rw = rw + 1
End If

End With
End If

End Function



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
Error 424 - Object Required [email protected] Excel Programming 2 December 30th 04 03:38 PM
424 Object required error J_J Excel Programming 4 November 7th 04 05:34 AM
Object Required Error Steph[_3_] Excel Programming 3 August 13th 04 03:26 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 01:44 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"