Error 1004
You don't have to use the vlookup function to do what you want to do. The
following function counts the number of occurances of a match, but you can
alter it to do whatever you like.
Function Count_Duplicates(Ip_Range As range, Cell_Chk As range) As Integer
Dim i As Integer, j As Integer, temp As Integer
' Function compares a cell (Cell_Chk) to a range
' (IP_Range) and returns the number of occurances
' of the cell value found in the range.
For j = 1 To Ip_Range.Columns.count
For i = 1 To Ip_Range.Rows.count
If Trim(Ip_Range(i, j)) = Trim(Cell_Chk(1, 1)) Then temp = temp
+ 1
Next i
Next j
Count_Duplicates = temp
End Function
The above function returns zero with no matches. You can avoid the returned
error.
"MJRay" wrote:
I have an error handling process within a For...next loop. If error 1004
occurs then the error handler gets activated. Once the error handling is
finished the next record in the loop is processed.
I am using a vlookup to match a value in a column. If the value does not
exist, I get error 1004. I put the following error handler in which works
great the first time through the loop but if a second lookup value does not
exist the error handling process does not get activated.
For nr = 2 to lnr
On Error GoTo errorhandler:
mtch = Application.WorksheetFunction.VLookup( _
snamt, ActiveSheet.Range("T1:T5000"), 1, False)
code to process if there is a match as a result of the lookup
errorhandler:
If Err = 1004 Then
Worksheets("NABTemp").Activate
Rows(nr).Select
With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End With
Err.Clear
End If
next nr
Thanks,
Mike
|