0

I've been looking for an answer to this for a little while now. I'm referencing the last answer (by control freak) to this question Excel VBA - How to Redim a 2D array? in my compiling problems.

Dim arrMachineVision(10, 4)
arrMachineVision = ReDimPreserve(arrMachineVision, machineVisionCount - 1, 4)

Above is my code line that won't compile and it is telling me that this can't be assigned to the array. I know in Java you have to make a temporary array and then copy values over and then reassign the original array to the temp array and then set that array null. This is what I thought the function was doing but then after it is done it can't be assigned to the original array. I'm wondering what I'm doing wrong.

The reason I'm going through this function is because I need to resize the first dimension in my 2d array and the normal redim won't do that for me.

Community
  • 1
  • 1
User3005
  • 5
  • 1
  • 4
  • You can only change the last value with redim preserve. – Scott Craner Feb 08 '16 at 16:47
  • in the accepted answer in the link you posted, it states that you can't declare an array with the exact size and redim it later. Try to change your array declaration to just "Dim arrMachineVision()". You should also specify a data type, because without it, it will be a variant. – Jeremy Feb 08 '16 at 16:50
  • I'm referencing not the accepted answer but the other one that actually provided somewhat of a solution. – User3005 Feb 08 '16 at 16:54
  • I understand. I'm saying to look in the accepted answer for how to declare the array properly. – Jeremy Feb 08 '16 at 17:07
  • If you want to redim an array then you will need to transpose the array; `Dim arrMachineVision()` then you can redim it `ReDim arrMachineVision(4,10)` then you can do this `ReDim Preserve arrMachineVision(4, machineVisionCount - 1)` – Scott Craner Feb 08 '16 at 18:08

0 Answers0