dim nrec,i
nrec = Datagridview1.Rowcount()
for i = 0 to nrec - 1
.........
next