Skip to Content
avatar image
Former Member

Type mismatch oddity

Hello everyone

I am trying to write a program with VBScript for transaction ZST1. I want to combine duplicate materials and calculate total quantity of each material, and finally remove extraneous rows. My script works fine until I try to process something like 300 or more rows, and I get 'Type mismatch: CInt' error. Script first sorts the rows by material in descending order, then get fed to this loop:

index = 0
mlast = table.getCellValue(0, "MATERIAL")
total = 0

For row = 0 To table.rowCount - 1
     mnext = table.getCellValue(row, "MATERIAL")
     qnext = CInt(table.getCellValue(row, "QUANTITY"))

     If mlast = mnext Then
          total = total + qnext
     Else
          Call table.ModifyCell(index, "MATERIAL", mlast)
          Call table.ModifyCell(index, "QUANTITY", CStr(total))
          index = index + 1
          mlast = mnext
          total = qnext
     End If

     If mlast = "" Then
          table.DeleteRows(CStr(index) + "-" + CStr(table.rowCount - 1))
          Exit For
     End If
Next

There's only one instance of CInt there so it's easy to see where it fails, but I can't figure out why! Quantity column contains only numeric values, and I'm certain that the problem cannot be integer overflow. It seems that only when there's enough rows to deal with, the script just fails.

Could anyone help me to debug this thing?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Dec 22, 2015 at 12:29 PM

    Hello.

    May you should add your code in Excel VBA.

    When it got failed you can check which value cause it.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Holger Köhn

      So the rows are in fact cached to disk. That does make sense. But is scrolling really the only way to get all rows? It seems kind of a dirty hack to me.