-
March 7th, 2014, 06:26 AM
#1
writ to an excel file
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.
Code:
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
-
March 7th, 2014, 07:34 AM
#2
Re: writ to an excel file
would this work
Code:
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)
Dim arrValues() As Date = objRng.Value
' Use a For..Next loop to write arrValues
' to the first row of objSheet
For i As Integer = 1 To 5
objSht.Cells.Item(1, i).Value2 = arrValues(i - 1)
Next
Call WritetoExcel()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|