Hi guys can you help me in this one? I can add cell values in Datagrid using their column address or column name but I want to add the columns which contain a specific word for example I want to add all cells with a column name containing "Amount"

        Dim rw = 0
        Dim ax = Form1.DataGridView1.RowCount - 1
        Dim cl = 1
        Dim dy = Form1.DataGridView1.ColumnCount

        Do
            Do

                If Form1.DataGridView1.Columns(cl).Name.Contains("Amount") = True Then

                    Form1.DataGridView1.Rows(rw).Cells("Final Computation").Value += Form1.DataGridView1.Rows(rw).Cells(cl).Value

                    cl = cl + 1

                Else

                    cl = cl + 1

                End If


            Loop While (cl < dy)

            rw = rw + 1
        Loop While (rw < ax)

It says Index is out of range.

Problem solved.............

 Dim t As Integer
        For i As Integer = 0 To Form1.DataGridView1.Rows.Count - 2

            For j As Integer = 0 To Form1.DataGridView1.Columns.Count - 1

                If Form1.DataGridView1.Columns(j).Name.Contains("Amount") = True Then

                    t += Form1.DataGridView1.Rows(i).Cells(j).Value

                End If

            Next
            Form1.DataGridView1.Rows(i).Cells("Final Computation").Value = t
            t = 0
        Next
This question has already been answered. Start a new discussion instead.