Extract part of an array and create a new array

DonEB

Board Regular
Joined
Apr 26, 2016
Messages
128
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 can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
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,215,126
Messages
6,123,200
Members
449,090
Latest member
bes000

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