B
broogle
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
"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