Subscript out of range after Cell.value call

%3CLINGO-SUB%20id%3D%22lingo-sub-1899095%22%20slang%3D%22en-US%22%3ESubscript%20out%20of%20range%20after%20Cell.value%20call%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1899095%22%20slang%3D%22en-US%22%3E%3CP%3EError%20happens%20after%20macro%20runs%20to%20completion%20and%20then%20is%20supposed%20to%20print%20data%20to%20excel.%20Macro%20produces%20a%2010x10%20array%20of%20values%20and%20is%20sent%20to%20the%20below%20routine.%20All%20the%20values%20do%20print%20but%20after%20completion%2C%20a%20subscript%20out%20of%20range%20error%20occurs.%20Err.description%20is%20blank%2C%20debug%20does%20not%20highlight%20any%20code%2C%20and%20I%20know%20the%20routine%20is%20written%20appropriately%20especially%20because%20it%20works%20right%20up%20until%20it%20finishes.%20Activate%20doesn't%20work%2C%20enableEvents%20does%20nothing%2C%20on%20error%20statements%20are%20not%20triggered%2C%20changing%20the%20printing%20area%20to%205x5%20results%20in%20same%20error%20after%20completion.%20Problem%20initially%20started%20by%20the%20program%20pausing%2C%20me%20switching%20screens%20and%20returning%20started%20it%20up%20again.%20Repairing%2C%20resetting%2C%20and%20reinstalling%20Excel%20didn't%20do%20it%20either.%20Thoughts%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDim%20i%20As%20Integer%2C%20j%20As%20Integer%2C%20str%20As%20String%3CBR%20%2F%3EFor%20i%20%3D%201%20To%2010%3CBR%20%2F%3EFor%20j%20%3D%201%20To%2010%3CBR%20%2F%3ECells(j%2C%20i).Value2%20%3D%20world(i%2C%20j).getVector%3CBR%20%2F%3ENext%20j%3CBR%20%2F%3ENext%20i%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1899095%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1899430%22%20slang%3D%22de-DE%22%3ESubject%3A%20Subscript%20out%20of%20range%20after%20Cell.value%20call%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1899430%22%20slang%3D%22de-DE%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F872889%22%20target%3D%22_blank%22%3E%40saintcolius%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eshould%20actually%20go%20through%20(untested)%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EDim%20i%20As%20Integer%2C%20j%20As%20Integer%2C%20str%20As%20String%0AFor%20i%20%3D%201%20To%2010%0AFor%20j%20%3D%201%20To%2010%0A10%0ACells(j%2C%20i).Value2%20%3D%20world(i%2C%20j).getVector%0ANext%20j%0ANext%20i%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EFor...Next%20statement%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice%2Fvba%2Flanguage%2Freference%2Fuser-interface-help%2Ffornext-statement%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice%2Fvba%2Flanguage%2Freference%2Fuser-interface-help%2Ffornext-statement%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20be%20happy%20to%20know%20if%20I%20could%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENikolino%3C%2FP%3E%3CP%3EI%20know%20I%20don't%20know%20anything%20(Socrates)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E*%20Kindly%20Mark%20and%20Vote%20this%20reply%20if%20it%20helps%20please%2C%20as%20it%20will%20be%20beneficial%20to%20more%20community%20members%20reading%20here.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

Error happens after macro runs to completion and then is supposed to print data to excel. Macro produces a 10x10 array of values and is sent to the below routine. All the values do print but after completion, a subscript out of range error occurs. Err.description is blank, debug does not highlight any code, and I know the routine is written appropriately especially because it works right up until it finishes. Activate doesn't work, enableEvents does nothing, on error statements are not triggered, changing the printing area to 5x5 results in same error after completion. Problem initially started by the program pausing, me switching screens and returning started it up again. Repairing, resetting, and reinstalling Excel didn't do it either. Thoughts?

 

Dim i As Integer, j As Integer, str As String
For i = 1 To 10
For j = 1 To 10
Cells(j, i).Value2 = world(i, j).getVector
Next j
Next i

1 Reply
Highlighted

@saintcolius 

should actually go through (untested)

Dim i As Integer, j As Integer, str As String
For i = 1 To 10
For j = 1 To 10
Cells(j, i).Value2 = world(i, j).getVector
Next j
Next i

 

For...Next statement

https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/fornext-statement

 

I would be happy to know if I could help.

 

Nikolino

I know I don't know anything (Socrates)

 

* Kindly Mark and Vote this reply if it helps please, as it will be beneficial to more Community members reading here.