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.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,627
Messages
5,838,440
Members
430,548
Latest member
hh_dh2001

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top