Greetings!
I have seen alot of code on this forum for exporting Datagrid data to excel, which is what I am trying to achieve. However, I have not been able successfully adapt any code to work. I keep getting an "Invalid Row Number". It looks like its going to work where the field name gets populated in cell A1 and then all the values for field one get populated but when it should iterate to B1, I get the error.
Any ideas?
Thanks,
dolo
Code:Private Sub cmdExport_Click() Dim Appli As New Excel.Application Dim C As Integer Dim F As Integer Appli.SheetsInNewWorkbook = 1 Appli.Visible = True Appli.Workbooks.Add For C = 0 To DataGrid1.Columns.Count - 1 DataGrid1.Col = C Appli.ActiveSheet.Cells(1, C + 1).Value = DataGrid1.Columns(C).Caption For F = 1 To DataGrid1.ApproxCount Appli.ActiveSheet.Cells(F + 1, C + 1).Value = DataGrid1.Text DataGrid1.Row = DataGrid1.Row + 1 Next F Next C End Sub




Reply With Quote