The VB
For
loop runs from the start to the end value
inclusive - so this:
For index As Integer = 0 To 3
Console.Write(index.ToString & " ")
Next
Will print
0 1 2 3
So your code
For Z1 = 0 To DataGridView1.RowCount
will work from the first index to the one after the last index inclusive, and your app throws an exception. Try:
For Z1 = 0 To DataGridView1.RowCount - 1