Array does not like #NAME?

Reset

Board Regular
Joined
Apr 16, 2010
Messages
227
I am running the following code that looks for a user input value (fname) in a specified column (cname). If it's there, another array notes the row. Then I go back and fill the array with the cell values of the rows with hits (Note: thanks to VoG on last issue). Then it's all dumped into another sheet (workbook=b2name and sheet=s2name). Here's the code:

m = Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByColumns).Column
a = Application.WorksheetFunction.CountA(Columns(cname))
ReDim rcount(a) As Integer
For x = 1 To a
If InStr(1, Cells(x, cname), fname, 1) Then
inc = inc + 1
rcount(inc) = x
End If
Next x
ReDim rdata(inc, m) As String
For x = 1 To inc
For y = 1 To m
rdata(x, y) = Cells(rcount(x), y)
Next y
Next x
Workbooks(b2name).Activate
Sheets(s2name).Activate
For x = 1 To inc
For y = 1 To m
Cells(x, y) = rdata(x, y)
Next y
Next x

However, when it reaches a cell with #NAME? I get a Run-time error '13': Type mismatch. In the editor the highlighted area "rdata(x, y) = Cells(rcount(x), y) also gives Cells(rcount(x), y) = Error 2029. Does anyone know how to ignore this? I could just fill the spot in the array with a dummy value. Thanks.
 

Some videos you may like

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
If Not IsError(Cells(rcount(x), y)) Then
    rdata(x, y) = Cells(rcount(x), y)
End If
 

Watch MrExcel Video

Forum statistics

Threads
1,109,522
Messages
5,529,328
Members
409,863
Latest member
stacy09
Top