For J As Integer = 0 To DataGridView1.ColumnCount = -1
and
For i As Integer = 0 To DataGridView1.Rows.Count = -2
should be
For J As Integer = 0 To DataGridView1.ColumnCount - 1
and
For i As Integer = 0 To DataGridView1.Rows.Count - 2
respectively.
A quicker way to solve this kind of issues is to use debugging; put a breakpoint at the beginning of the
Try
block, start a debug session (F5), and execute line-by-line, watching for the program flow. You will quickly find out that your loops may not behave the way they should.