### A_Index fails in Excel COM, manual increment works

Posted:

**30 Nov 2018, 22:58**The code below works

This code fails

On the first time through, after it pops up 1,1 it throws this error:

Clearly, I'm missing something. But, what?

Code: Select all

```
ex:=ComObjActive("Excel.Application")
Loop % 26*10+12 ; this is columns
{
c++
Loop 1506 ; this is rows
{
r++
MsgBox % r "," c
formula:=ex.Cells(r, c).formula
If StrLen(formula)>80
ex.Cells(r, c).formula:="=IF(A5=""CP""," SubStr(formula,2) ",IF(A5=""Stats Sum"",(INDIRECT(""R"" & ROW()-MOD(ROW(),19)+7 & ""C"" & COLUMN(),FALSE)+$B$2)*VLOOKUP(INDIRECT(""R"" & ROW()-MOD(ROW(),19)+6 & ""C1"",FALSE),CPMultiplier!$A:$B,2,FALSE)+(INDIRECT(""R"" & ROW()-MOD(ROW(),19)+8 & ""C"" & COLUMN(),FALSE)+$C$2)*VLOOKUP(INDIRECT(""R"" & ROW()-MOD(ROW(),19)+6 & ""C1"",FALSE),CPMultiplier!$A:$B,2,FALSE)+(INDIRECT(""R"" & ROW() & ""C"" & COLUMN()-MOD(COLUMN(),17)+1,FALSE)+$D$2)*VLOOKUP(INDIRECT(""R"" & ROW()-MOD(ROW(),19)+6 & ""C1"",FALSE),CPMultiplier!$A:$B,2,FALSE),""N/A""))"
}
r:=0
}
return
```

Code: Select all

```
ex:=ComObjActive("Excel.Application")
Loop % 26*10+12 ; this is columns
{
c:=A_Index
Loop 1506
{
r:=A_Index
MsgBox % r "," c
formula:=ex.Cells(r,c).formula
If StrLen(formula)>80
ex.Cells(r, c).formula:="=IF(A5=""CP""," SubStr(formula,2) ",IF(A5=""Stats Sum"",(INDIRECT(""R"" & ROW()-MOD(ROW(),19)+7 & ""C"" & COLUMN(),FALSE)+$B$2)*VLOOKUP(INDIRECT(""R"" & ROW()-MOD(ROW(),19)+6 & ""C1"",FALSE),CPMultiplier!$A:$B,2,FALSE)+(INDIRECT(""R"" & ROW()-MOD(ROW(),19)+8 & ""C"" & COLUMN(),FALSE)+$C$2)*VLOOKUP(INDIRECT(""R"" & ROW()-MOD(ROW(),19)+6 & ""C1"",FALSE),CPMultiplier!$A:$B,2,FALSE)+(INDIRECT(""R"" & ROW() & ""C"" & COLUMN()-MOD(COLUMN(),17)+1,FALSE)+$D$2)*VLOOKUP(INDIRECT(""R"" & ROW()-MOD(ROW(),19)+6 & ""C1"",FALSE),CPMultiplier!$A:$B,2,FALSE),""N/A""))"
}
}
return
```

Code: Select all

```
---------------------------
Script.ahk
---------------------------
Error: 0x800A03EC -
Source: (null)
Description: (null)
HelpFile: (null)
HelpContext: 0
Specifically: Cells
Line#
002: Loop,26*10+12
003: {
004: c := A_Index
005: Loop,1506
006: {
007: r := A_Index
008: MsgBox,r "," c
---> 009: formula := ex.Cells(r, c).formula
010: if StrLen(formula)>80
011: ex.Cells(r, c).formula:="=IF(A5=""CP""," SubStr(formula,2) ",IF(A5=""Stats Sum"",(INDIRECT(""R"" & ROW()-MOD(ROW(),19)+7 & ""C"" & COLUMN(),FALSE)+$B$2)*VLOOKUP(INDIRECT(""R"" & ROW()-MOD(ROW(),19)+6 & ""C1"",FALSE),CPMultiplier!$A:$B,2,FALSE)+(INDIRECT(""R"" & ROW()-MOD(ROW(),19)+8 & ""C"" & COLUMN(),FALSE)+$C$2)*VLOOKUP(INDIRECT(""R"" & ROW()-MOD(ROW(),19)+6 & ""C1"",FALSE),CPMultiplier!$A:$B,2,FALSE)+(INDIRECT(""R"" & ROW() & ""C"" & COLUMN()-MOD(COLUMN(),17)+1,FALSE)+$D$2)*VLOOKUP(IND
012: }
013: }
014: Return
015: Exit
016: Exit
Continue running the script?
---------------------------
Yes No
---------------------------
```