Thread: find problem
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
john john is offline
external usenet poster
 
Posts: 97
Default find problem

Help - I am trying to search a range row by row and find
the matching item in another range and then compare some
data in adjacent columns, and then if ok copy some other
data from one sheet to the next. I am getting an error
"object variable or With block variable not set" on the
if iserror statement - which is inteded to determine if
the item is missing from the second range.

thanks,

John

Option Explicit
Sub Compare()
'
Dim badbatch(100)
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim nomrow As Integer
Dim startkm As Integer
Dim numkm As Integer
Dim startnom As Integer
Dim colnom As Integer
Dim colkm As Integer
Dim km As Range
Dim nom As Range
Dim tender As String
'
' Define ranges
'
Range("km").CurrentRegion.Name = "km"
Range("nom").CurrentRegion.Name = "nom"
numkm = Range("km").End(xlDown).Row - Range("km").Row
startkm = Range("km").Row
colkm = Range("km").Column
startnom = Range("nom").Row
colnom = Range("nom").Column
i = 0
For j = startkm To numkm + startkm
Sheets("km").Select
tender = Sheets("km").Cells(j, colkm).Text
If IsError(Sheets("nominated").Range("nom").Find
(tender).Row) _
Then GoTo badtender
nomrow = Sheets("nominated").Range("nom"). _
Find(Sheets("km").Cells(j, colkm).Text).Row
If Sheets("km").Cells(j, colkm).Offset(0, 4).Value < _
Sheets("nominated").Cells(nomrow, colnom + 4).Value _
Then GoTo badvolume
Sheets("nominated").Cells(nomrow, colnom + 2) = _
Sheets("km").Cells(j, colkm).Offset(0, 2).Value
Sheets("nominated").Cells(nomrow, colnom + 3) = _
Sheets("km").Cells(j, colkm).Offset(0, 3).Value
GoTo nextj
badvolume:
i = i + 1
badbatch(i) = Cells(j, colkm).Text
GoTo nextj
badtender:
i = i + 1
badbatch(i) = Cells(j, colkm).Text
GoTo nextj
nextj:
Next j
If i 0 Then MsgBox ("Batch not found") Else GoTo done
Sheets("badtenders").Select
For k = 1 To i
Cells(k + 1, 1).Value = badbatch(k)
Cells(2, 5).Value = startkm
Cells(2, 6).Value = numkm
Next k
done:
End Sub