PDA

View Full Version : Macro crash when extending date range



Seeboo
08-17-2021, 01:43 AM
Hello,


I have a macro copying the data in one file from the data from the other file.
In the one version, the macro works perfectly. I wanted to use another file for a larger date range, but the macro crashes. Could someone have a look and try to explain which part of the macro I need to change in order for it to work properly?


Attached I am sending two pairs of files:
- the first pair: ((TEST) Daily Production Plan.xlsb, (TEST) Plan seq.xlsb) - macro does not work
- the second pair: (Daily Production Plan (2) .xlsb, Plan seq (2) .xlsx) - macro works properly


The macro is run by pressing the button from the "Daily Production Plan" file, previously you have to change the path to the "Plan seq" file in the vba code.

p45cal
08-17-2021, 06:56 AM
It's down to this line:
If x = 2 Then b(i, 7) = 1 Else b(i, 7) = IIf(b(i, 5) = b(i - 1, 5), b(i - 1, 7), b(i - 1, 7) + 1)
In the one that crashes, the first time that line is executed x=19 and i=1, so when
b(i - 1, 5)
is encountered, that line resolves to:
b(0, 5)
and there is no b(0), subscript out of range.

It might be an idea to take the code out of the sheet code-module into a standard code module.

p45cal
08-17-2021, 07:32 AM
This is just a guess (I haven't looked deeply into the workings of the macro), perhaps instead of asking:
If x = 2 Then
maybe:
If i = 1 Then
?

Seeboo
08-18-2021, 01:31 AM
This is just a guess (I haven't looked deeply into the workings of the macro), perhaps instead of asking:
If x = 2 Then
maybe:
If i = 1 Then
?
Unfortunately it is does not work.