Slice array / Application.Index type mismatch error

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,922
Office Version
  1. 365
Platform
  1. Windows
Hi,

Following code errors on highlighted line with Error 13, type mismatch:
Rich (BB code):
Sub Test1()

    Dim x       As Long
    Dim arr()   As Variant

    With Sheets("Sheet1")
        x = .Cells(.Rows.Count, 1).End(xlUp).Row
        arr = .Cells(25, 1).Resize(x - 24, 2).Value
    End With
    
    For x = LBound(arr, 1) To UBound(arr, 1)
        Select Case arr(x, 2)
            Case Is = 1, 2
            Case Else: arr(x, 1) = Null
        End Select
    Next x
    
    With Sheets("Sheet2")
        With .Cells(.Rows.Count, 1).End(xlUp).Offset(1).Resize(UBound(arr, 1))
            .Value = Application.Index(arr, 0, 1)
            .SpecialCells(xlCellTypeBlanks).Delete xlUp
        End With
    End With
    
    Erase arr
    
End Sub
Read various online forums for answers (e.g. declare arr without brackets, size limitations) but nothing suggested removes this error and the data is contained in A25:B35 in Sheet1 only

The below code runs fine (in same workbook), without error, so can't tell if it's syntax related:
Rich (BB code):
Sub Test()
  Dim arr() As Variant
  arr = Cells(1, 1).Resize(3, 2).Value
  Cells(1, 4).Resize(UBound(arr, 1)).Value = Application.Index(arr, 0, 1)
  Cells(1, 5).Resize(UBound(arr, 1)).Value = Application.Index(arr, 0, 2)
  Erase arr
End Sub
Any help on removing the error in the top macro?

TIA, Jack
 
Last edited:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
arr(x,1) = vbNullString NOT arr(x,1) = Null

Code is working now
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,876
Members
452,363
Latest member
merico17

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
Back
Top