Extract part of an array and create a new array

DonEB

Board Regular
Joined
Apr 26, 2016
Messages
133
Office Version
  1. 2019
Platform
  1. Windows
Attempting to create a smaller array from a larger array. I feel I've been able to get parts of it to work... except for the most critical part.
VBA Code:
'NOTE:  inarray was passed into this subroutine as follows:  Sub PreComboReset(ByRef inarray As Variant)

Dim inarr1 as Variant

'NOTE: use LastRowb because this range could change and is inside the larger array.  
LastRowb = Sheets("sheet2").Range("B5:B24").Find(What:="*", After:=Sheets("sheet2").Range("B5:B24").Cells(1, 1), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

For i = 4 To (LastRowb - 1)              
     For j = 2 To LastRowb

         'Debug.Print inarray(i, j)         'I used this debug.print to verify that I was getting the data I was expecting to get.

          inarr1(i-3, j-1)  = inarray(i, j)              'copies contents of one array into another

     Next j
 Next i

Unfortunately, when I get to "inarr1(i-3, j-1) = inarray(i, j)", I get a "run-time error 13, type mismatch".

As an FYI, inarray was previous defined and populated as follows in a preceding subroutine:
VBA Code:
Dim inarray As Variant
inarray = Sheets("Sheet2").Range("A2:X24").Value2

Any thoughts would be appreciated.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Replace:
VBA Code:
Dim inarr1 as Variant
with:
VBA Code:
ReDim inarr1(1 To UBound(inarray) - 3, 1 To UBound(inarray, 2) - 1) As Variant

Edit - or after the LastRowb line:
VBA Code:
ReDim inarr1(1 To LastRowb - 4, 1 To LastRowb - 1) As Variant
 
Last edited:
Upvote 0
Solution
John,
Thank you very much. This is exactly what I was looking for.
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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