CREATE CURSOR crsResult (account C(10),amount N(15,2), percentage N(6,2), ClassCode C(5)) SELECT MyTable INDEX ON Account+ClassCode TAG MyTable && With proper conversion if they are different types SET ORDER TO MyTable GO TOP DO WHILE .NOT. EOF() m.nRecNo = RecNo() m.changedCond = Account+ClassCode && With proper conversion if they are different types SUM Ammount TO nTotalAmm WHILE m.changedCond == Account+ClassCode GO m.nRecNo DO WHILE m.changedCond == Account+ClassCode *** You need to check IF the nTotalAmm is not equal to zero. SELECT crsResult APPEND BLANK REPLACE Account WITH MyTable.Account,; Ammount WITH MyTable.Ammount,; ClassCode WITH MyTable.ClassCode,; Percentage WITH IIF(nTotalAmm==0,100,ROUND(Ammount/nTotalAmm,2)) SELECT MyTable SKIP ENDDO ENDDOWhy you should do that? I am not very familiar with VBA but doesn't it supports SQL-SELECT commands?