write to an excel file

rjhe22

Well-known member
Joined
May 22, 2008
Messages
88
Programming Experience
Beginner
hi
i have this code that reads an excel file matches dates and what i need to do it get it to write to another excel file one the date macthes.
VB.NET:
 Dim objExcel As New Excel.Application
        Dim objWrkBk As Excel.Workbook
        Dim objSht As Excel.Worksheet
        Dim objRng As Excel.Range
        Dim strCol, strCell As String
        Dim maxCol, maxRow As Integer
        Dim iRow, iCol As Integer

        maxRow = 12
        maxCol = 2
        objWrkBk = objExcel.Workbooks.Open(txNametFile1.Text)
        objSht = objWrkBk.Worksheets(1)
        objExcel.Visible = True
        For iCol = 2 To maxCol
            For iRow = 2 To maxRow
                MessageBox.Show("This is column " & objSht.Cells(iRow, maxCol).Value)
                strCol = Chr(Asc(iCol) + 16)
                strCell = strCol + iRow.ToString
                objRng = objSht.Range(strCell)
                If objRng.Value = DateTimePicker1.Value Then
                    MsgBox(DateTimePicker1.Value)
                    Call WritetoExcel()
                Else

                    MsgBox(objRng.Value)
                End If



            Next
        Next
i have written to an excel file before naming the cell i want it to right to but i dont think that will work this time. when it hits the dat i want it to copy the data from row a and b and write it to new file in row a and b and keep going all the way down this the file is read.
Whats the best way for this to be done
 
Back
Top