Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Problem with 'Find' | Excel Discussion (Misc queries) | |||
Find last row macro problem | Excel Discussion (Misc queries) | |||
problem with FIND | Excel Worksheet Functions | |||
find problem | Excel Programming | |||
Problem with FIND | Excel Programming |