datagridview and columns RRS feed

  • Question

  • Hello 

    i have a code but the column"Formula QoS" didn't shown

     Dim ShtRange As Range
                        Dim LastCol5 As Integer
                        Dim LastRow As Integer
                        Dim aRow As Excel.Range
                        Dim dt As New System.Data.DataTable
                        LastCol5 = Chargement_de_données.xlWorkSheet.Cells(1, Chargement_de_données.xlWorkSheet.Columns.Count).End(XlDirection.xlToLeft).Column
                        LastRow = Chargement_de_données.xlWorkSheet.Range("A" & Chargement_de_données.xlWorkSheet.Rows.Count).End(XlDirection.xlUp).Row
                        dt.Columns.Add("Cell Name")
                        dt.Columns.Add("Formula QOS")
                        ShtRange = .Range(.Cells(1, LastCol), .Cells(LastRow, LastCol))
                        For Each aRow In Chargement_de_données.xlWorkSheet.UsedRange.Rows
                            If aRow.Row <> 1 Then
                                'Debug.Print(aRow.Cells(1, 3) & aRow.Cells(1, 10))
                                'add the code here to build the datatable
                                Dim dr As DataRow = dt.NewRow()
                                dr("Cell Name") = aRow.Cells(1, 3).Value
                                dr("Formula QOS") = ShtRange.Value
                            End If
                        Next aRow
                        DataGridView1.DataSource = dt

    please help me :)

    Monday, April 27, 2015 6:23 PM


  • Hi tamaratheo,

    >>ShtRange = .Range(.Cells(1, LastCol), .Cells(LastRow, LastCol))<<

    Which worksheet does '.Range' refere to? I would suggest that you specific it more clearly. For example, we can use code below to refer to the range on a specific worksheet:


    The system.Object[,] seems that the 'shtRange' is not a single cell. Please debug the code to see the value 'LastCol' and 'LastRow' and ensure the shtRange is a single cell.

    Regards & Fei

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, April 28, 2015 7:10 AM