1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim xlApp As New Microsoft.Office.Interop.Excel.Application
Dim xlWb, bilan As Microsoft.Office.Interop.Excel.Workbook
Dim xlSh, feubilan As Microsoft.Office.Interop.Excel.Worksheet
Dim i As Integer = 1
Dim j As Integer = 2
xlWb = xlApp.Workbooks.Open("C:\Documents and Settings\Lucas\Mes documents\documents test\BALXLS\ST.xlsx")
bilan = xlApp.Workbooks.Open("C:\Documents and Settings\Lucas\Mes documents\documents test\test\testf.xlsx")
xlSh = CType(xlWb.Worksheets(1), Worksheet)
feubilan = CType(bilan.Worksheets(1), Worksheet)
Do While ((CStr(Microsoft.VisualBasic.Left(xlSh.Cells(i, 1).value, 1)) <> "6") And (CStr(feubilan.Cells(j, 1).value) <> "."))
If (CStr(feubilan.Cells(j, 1).value) <> ".") Then
'206
If (xlSh.Cells(i, 1).value = feubilan.Cells(j, 1).value) Then
feubilan.Cells(j, 4).value = xlSh.Cells(i, 4).value - xlSh.Cells(i,3).value
i = i + 1
ElseIf (xlSh.Cells(i, 1).value > CObj(feubilan.Cells(j, 1).value)) Then
If (xlSh.Cells(i, 1).value < feubilan.Cells(j + 1, 1).value) Then
feubilan.Rows(j + 1).insert()
feubilan.Cells(j + 1, 1).value = xlSh.Cells(i, 1).value
feubilan.Cells(j + 1, 2).value = xlSh.Cells(i, 2).value
feubilan.Cells(j + 1, 4).value = xlSh.Cells(i, 4).value - xlSh.Cells(i, 3).value
j = j + 1
i = i + 1
ElseIf (Microsoft.VisualBasic.Left(xlSh.Cells(i, 1).value, 4) < feubilan.Cells(j + 1, 1).value) Then
feubilan.Rows(j + 1).insert()
feubilan.Cells(j + 1, 1).value = xlSh.Cells(i, 1).value
feubilan.Cells(j + 1, 2).value = xlSh.Cells(i, 2).value
feubilan.Cells(j + 1, 4).value = xlSh.Cells(i, 4).value - xlSh.Cells(i, 3).value
j = j + 1
i = i + 1
ElseIf (CStr(feubilan.Cells(j + 1, 1).value) = ".") Then
feubilan.Rows(j + 1).insert()
feubilan.Cells(j + 1, 1).value = xlSh.Cells(i, 1).value
feubilan.Cells(j + 1, 2).value = xlSh.Cells(i, 2).value
feubilan.Cells(j + 1, 4).value = xlSh.Cells(i, 4).value - xlSh.Cells(i, 3).value
j = j + 1
i = i + 1
End If
Else
j = j + 1
End If
Else
j = 2
End If
Loop
xlWb.Saved = True
bilan.Saved = False
xlWb.Close()
bilan.Close()
End Sub |
Partager