大型Excel数据传输宏

时间:2015-07-02 13:14:33

标签: excel vba excel-vba

对于这个宏,我有Sheet1,这是一个包含从1月1日到30日的数据的电子表格。每月的每一天都有大约100个信用分录。我正在尝试编写一个宏,它将循环显示当月1日到30日,同时读取条目是发票类型,内部没有“CAN”字符串等等。但是,在此一段代码,我得到一个无限循环,msgbox提示“0”,无限次。我想要的是对表1中的值进行求和,然后输入到我的数据输入表(我自己可以编写的数据输入位,我仍然试图将这些值加总)。如果有人发现此代码有任何明显问题,请告诉我。因此,举例来说,如果第一个有20个信用分录,那20个条目分别为100个......我希望将4,000个输入到我的数据输入表中。然后,如果第二个有30,我想要6,000输入我的数据输入表的下一个值。

Private Sub CommandButton1_Click()

    Dim dateCheck As String
    Dim shipDay As Date
    Dim L As Integer
    Dim I As Integer
    Dim S As Integer
    Dim search As String
    Dim usaTotal As Long
    Dim usaCredit As Long
    Dim usaDebit As Long
    L = 10
    I = 2

    dateCheck = InputBox("What Date is Ship Day 1?", "Ship Day Entry")

    If IsDate(dateCheck) Then shipDay = DateValue(dateCheck) _
    Else: MsgBox ("Invalid Date") ' Prompts user for ship day 1, and checks if actual date

    While Not Worksheets("Sheet1").Cells(I, 4).Value = "" ' Runs until all cell rows are accounted for

        For S = 0 To 29

            Do Until shipDay <> Worksheets("Sheet1").Cells(I, 4).Value ' Execute until new date

                search = Worksheets("sheet1").Cells(I, 6).Value ' Variable to use InStr to check for "CAN"

                If (((shipDay = Worksheets("Sheet1").Cells(I, 4).Value) And _
                    InStr(1, search, "CAN", vbBinaryCompare) = 0) _
                    And (Worksheets("Sheet1").Cells(I, 2).Text = "Invoice")) Then

                    'Check that date matches, and that it isn't Canada, and that order is an invoice

                    usaDebit = Worksheets("Sheet1").Cells(I, 11).Value ' Account for Debits
                    usaCredit = Worksheets("Sheet1").Cells(I, 12).Value ' Account for Credits

                    usaTotal = usaCredit - usaDebit  ' Calculate contribution

                End If
            Loop

        Next S

        shipDay = shipDay + S

        ' Will input code here that will input final usaTotal into respective spaces

        MsgBox (usaTotal)


    Wend ' End of Initial while not

End Sub

0 个答案:

没有答案