Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 以下VBA代码中断。我怎样才能让它继续运行? 选项库1 子准备文件() '步骤1:打开eDPSS的最终SPQ并找到最早的开始日期 将行计数设置为整数 将最后一行设置为整数 i=2 直到IsEmpty(单元格(i,1).值) i=i+1 环 LastRow=_Excel_Vba - Fatal编程技术网

Excel 以下VBA代码中断。我怎样才能让它继续运行? 选项库1 子准备文件() '步骤1:打开eDPSS的最终SPQ并找到最早的开始日期 将行计数设置为整数 将最后一行设置为整数 i=2 直到IsEmpty(单元格(i,1).值) i=i+1 环 LastRow=

Excel 以下VBA代码中断。我怎样才能让它继续运行? 选项库1 子准备文件() '步骤1:打开eDPSS的最终SPQ并找到最早的开始日期 将行计数设置为整数 将最后一行设置为整数 i=2 直到IsEmpty(单元格(i,1).值) i=i+1 环 LastRow=,excel,vba,Excel,Vba,以下VBA代码中断。我怎样才能让它继续运行? 选项库1 子准备文件() '步骤1:打开eDPSS的最终SPQ并找到最早的开始日期 将行计数设置为整数 将最后一行设置为整数 i=2 直到IsEmpty(单元格(i,1).值) i=i+1 环 LastRow=i-1 行计数=i-2 '步骤2:在记录中查找最早的开始日期 最早的日期 将FirstDate变为Date EarliestDate=CDate(Application.Min(范围(“K2:K”和LastRow))) FirstDate=最早

以下VBA代码中断。我怎样才能让它继续运行?
选项库1
子准备文件()
'步骤1:打开eDPSS的最终SPQ并找到最早的开始日期
将行计数设置为整数
将最后一行设置为整数
i=2
直到IsEmpty(单元格(i,1).值)
i=i+1
环
LastRow=i-1
行计数=i-2
'步骤2:在记录中查找最早的开始日期
最早的日期
将FirstDate变为Date
EarliestDate=CDate(Application.Min(范围(“K2:K”和LastRow)))
FirstDate=最早的日期
'步骤3:查找最早开始日期和指定月份之间的月数
将月份设置为整数
以整数表示的年份
NowMonth=InputBox(“请指定要计算的最近月份。”&vbNewLine&“注意:月份应仅介于1和12之间。”)
如果NowMonth<1或NowMonth>12,则
MsgBox“您输入的月份无效。”
出口接头
其他的
NowMonth=NowMonth
NowYear=InputBox(“请指定要计算的当前年份。”&vbNewLine&“注意:年份应以yyyy格式输入。”)
如果NowYear<2008或NowYear>Year(日期),则
MsgBox“有效年份应介于2008年和年之间”&年(日期)&“
出口接头
其他的
NowMonth=NowMonth
NowYear=NowYear
如果结束
如果结束
将日期变暗为日期
Dim MonthRange作为整数
NowDate=CDate(“1/”&NowMonth&“/”&NowYear)
EarliestDate=CDate(“1/”月(第一天)和“/”年(第一天))
MonthRange=圆形((现在日期-最早日期)/30.4)
'步骤4:准备输出文件
将MyPath设置为字符串
MyPath=ActiveWorkbook.Path&“\output.xls”
Set NewBook=工作簿。添加
ActiveWorkbook.SaveAs MyPath
工作表(“表1”)。选择
范围(“A1”)。选择
ActiveCell.FormulaR1C1=“基本价格”
范围(“B1”)。选择
ActiveCell.FormulaR1C1=“合同号”
范围(“C1”)。选择
ActiveCell.FormulaR1C1=“项目标题”
范围(“D1”)。选择
ActiveCell.FormulaR1C1=“合同开始”
范围(“E1”)。选择
ActiveCell.FormulaR1C1=“合同结束”
范围(“F1”)。选择
ActiveCell.FormulaR1C1=“ASPQ”
范围(“G1”)。选择
ActiveCell.FormulaR1C1=“交付数量”
范围(“G2”)。选择
ActiveCell.FormulaR1C1=“累计TD”
范围(“H2”)。选择
Dim StartMonth作为字符串
StartMonth=月(最早日期)和“/1/”年(最早日期)
ActiveCell.FormulaR1C1=开始每月
Selection.NumberFormat=“mmmyy”
将当前月份设置为字符串
对于i=1至蒙特兰奇
CurrentMonth=月(CDate(DateAdd(“m”,1,EarliestDate))、/1/“&年(CDate(DateAdd(“m”,1,EarliestDate)))
单元格(2,8+i)。值=当前月份
单元格(2,8+i).NumberFormat=“mmmyy”
EarliestDate=DateAdd(“m”,1,EarliestDate)
接下来我
活动工作簿。关闭
“捕获合同编号及其附带信息
将输出路径设置为字符串
OutputPath=ActiveWorkbook.Path&“\output.xls”
不作为字符串
将项目标题设置为字符串
以字符串开头
以字符串结尾
将ASPQ设置为双精度
j=1
对于j=1到最后一行
合同编号=单元格(j+1,1)。数值
ProjectTitle=单元格(j+1,2).值
ContractStart=单元格(j+1,11).值
ContractEnd=单元格(j+1,12).值
ASPQ=单元格(j+1,14)。数值
'将这些信息粘贴到输出文件中
Application.Workbooks.Open(OutputPath)
单元格(j+2,2)。值=合同编号
单元格(j+2,3)。值=项目标题
单元格(j+2,4)。值=合同开始
单元格(j+2,5)。值=结束
单元格(j+2,6)。值=ASPQ
ActiveWorkbook.Close SaveChanges:=True
逐月循环浏览账单摘要
'如果可以找到,请填写当月交付的数量
'如果找不到,请将数量设置为零
Dim Monhttag作为整数
Dim YearTag作为整数
将ActiveMonth设置为字符串
对于m=1至蒙特兰奇
Application.Workbooks.Open(OutputPath)
MonthTag=月份(单元格(2,7+m).值)
年标记=年(单元格(2,7+m).值)
选择案例蒙塔格
案例“1”
ActiveMonth=“JAN”&右侧(年号,2)
案例“2”
ActiveMonth=“FEB”&右侧(年号,2)
案例“3”
ActiveMonth=“MAR”&右侧(年号,2)
案例“4”
ActiveMonth=“APR”&右侧(年号,2)
案例“5”
ActiveMonth=“MAY”和Right(年号,2)
案例“6”
ActiveMonth=“JUN”和Right(年号,2)
案例“7”
ActiveMonth=“JUL”和Right(年号,2)
案例“8”
ActiveMonth=“AUG”&右侧(年号,2)
案例“9”
ActiveMonth=“SEP”&右侧(年号,2)
案例“10”
ActiveMonth=“OCT”&右侧(年号,2)
案件“11”
ActiveMonth=“NOV”&右侧(年号,2)
案例“12”
ActiveMonth=“DEC”&右侧(年号,2)
结束选择
ActiveWorkbook.Close SaveChanges:=True
将MyFolder设置为字符串
双倍调暗数量
尺寸和数量为双
Dim被发现为整数
未找到整数
MyFolder=ActiveWorkbook.Path&“\bill\”
如果Dir((MyFolder&“\”&YearTag&“\Bill\u Summary\u Report&“&ActiveMonth&“.xls”))”,则
Application.Workbooks.Open(MyFolder&“\”&YearTag&“\Bill\u Summary\u Report\u”&ActiveMonth&“.xls”)
工作表(“水泥”)。选择
'查找合同坐标
x=1
直到单元格(x,1)为止。Value=“Sno”
x=x+1
环
y=1
直到单元格(x,y)为止。Value=“合同”
y=y+1
环
'查找数量坐标
p=1
直到单元格(p,1)为止。Value=“产品”
p=p+1
环
q=1
直到单元格(p,q)为止。Value=“C数量”
q=q+1
环
'确定当月交付的数量
这一领域存在问题,因为一个间距可能会扭曲数据
'可能需要手动检查合同编号的多次出现!
n=1
SumFound=0
SumQty=0
直到IsEmpty(单元格(17+n,y).值)
如果ContractNo=单元格(17+n,y)。则为
发现=1
数量=单元(19+n,q).Va
Option Base 1

Sub PrepareIOFile()

'Step 1: Open Final SPQ for eDPSS and find the earliest start date
Dim rowCount As Integer
Dim LastRow As Integer

i = 2
Do Until IsEmpty(Cells(i, 1).Value)
i = i + 1
Loop
LastRow = i - 1
rowCount = i - 2

'Step 2: Find the earliest start date in the records
Dim EarliestDate As Date
Dim FirstDate As Date

EarliestDate = CDate(Application.Min(Range("K2:K" & LastRow)))
FirstDate = EarliestDate

'Step 3: Find the number of months between earliest start date and specified month
Dim NowMonth As Integer
Dim NowYear As Integer

NowMonth = InputBox("Please specify the most recent month to compute." & vbNewLine & "Note: Month should be between 1 and 12 only.")

If NowMonth < 1 Or NowMonth > 12 Then

    MsgBox "You have entered an invalid month."
    Exit Sub

Else

    NowMonth = NowMonth
    NowYear = InputBox("Please specify the current year to compute." & vbNewLine & "Note: The year should be entered in the yyyy format.")

    If NowYear < 2008 Or NowYear > Year(Date) Then

        MsgBox "The valid year should be between Year 2008 and Year " & Year(Date) & "."
        Exit Sub

    Else

        NowMonth = NowMonth
        NowYear = NowYear

    End If

End If

Dim NowDate As Date
Dim MonthRange As Integer

NowDate = CDate("1/" & NowMonth & "/" & NowYear)
EarliestDate = CDate("1/" & Month(FirstDate) & "/" & Year(FirstDate))
MonthRange = Round((NowDate - EarliestDate) / 30.4)

'Step 4: Prepare the output file
Dim MyPath As String
MyPath = ActiveWorkbook.Path & "\output.xls"

Set NewBook = Workbooks.Add
    ActiveWorkbook.SaveAs MyPath

Worksheets("Sheet1").Select

Range("A1").Select
ActiveCell.FormulaR1C1 = "Basic Price"
Range("B1").Select
ActiveCell.FormulaR1C1 = "Contract No"
Range("C1").Select
ActiveCell.FormulaR1C1 = "Project Title"
Range("D1").Select
ActiveCell.FormulaR1C1 = "Contract Start"
Range("E1").Select
ActiveCell.FormulaR1C1 = "Contract End"
Range("F1").Select
ActiveCell.FormulaR1C1 = "ASPQ"
Range("G1").Select
ActiveCell.FormulaR1C1 = "Qty Delivered"
Range("G2").Select
ActiveCell.FormulaR1C1 = "Cumulative TD"
Range("H2").Select

Dim StartMonth As String
StartMonth = Month(EarliestDate) & "/1/" & Year(EarliestDate)
ActiveCell.FormulaR1C1 = StartMonth
Selection.NumberFormat = "mmmyy"

Dim CurrentMonth As String
For i = 1 To MonthRange
    CurrentMonth = Month(CDate(DateAdd("m", 1, EarliestDate))) & "/1/" & Year(CDate(DateAdd("m", 1, EarliestDate)))
    Cells(2, 8 + i).Value = CurrentMonth
    Cells(2, 8 + i).NumberFormat = "mmmyy"
    EarliestDate = DateAdd("m", 1, EarliestDate)
Next i

ActiveWorkbook.Close

'Capture Contract no. and its accompanying information
Dim OutputPath As String
OutputPath = ActiveWorkbook.Path & "\output.xls"

Dim ContractNo As String
Dim ProjectTitle As String
Dim ContractStart As String
Dim ContractEnd As String
Dim ASPQ As Double

j = 1
For j = 1 To LastRow
    ContractNo = Cells(j + 1, 1).Value
    ProjectTitle = Cells(j + 1, 2).Value
    ContractStart = Cells(j + 1, 11).Value
    ContractEnd = Cells(j + 1, 12).Value
    ASPQ = Cells(j + 1, 14).Value

'Paste these information into the output file
Application.Workbooks.Open (OutputPath)

Cells(j + 2, 2).Value = ContractNo
Cells(j + 2, 3).Value = ProjectTitle
Cells(j + 2, 4).Value = ContractStart
Cells(j + 2, 5).Value = ContractEnd
Cells(j + 2, 6).Value = ASPQ

ActiveWorkbook.Close SaveChanges:=True

'Loop through the bill summaries month by month
'If can find, put the quantity delivered for that month
'If cannot find, set the quantity to zero
Dim MonthTag As Integer
Dim YearTag As Integer
Dim ActiveMonth As String

For m = 1 To MonthRange
    Application.Workbooks.Open (OutputPath)
    MonthTag = Month(Cells(2, 7 + m).Value)
    YearTag = Year(Cells(2, 7 + m).Value)

    Select Case MonthTag
        Case "1"
            ActiveMonth = "JAN" & Right(YearTag, 2)
        Case "2"
            ActiveMonth = "FEB" & Right(YearTag, 2)
        Case "3"
            ActiveMonth = "MAR" & Right(YearTag, 2)
        Case "4"
            ActiveMonth = "APR" & Right(YearTag, 2)
        Case "5"
            ActiveMonth = "MAY" & Right(YearTag, 2)
        Case "6"
            ActiveMonth = "JUN" & Right(YearTag, 2)
        Case "7"
            ActiveMonth = "JUL" & Right(YearTag, 2)
        Case "8"
            ActiveMonth = "AUG" & Right(YearTag, 2)
        Case "9"
            ActiveMonth = "SEP" & Right(YearTag, 2)
        Case "10"
            ActiveMonth = "OCT" & Right(YearTag, 2)
        Case "11"
            ActiveMonth = "NOV" & Right(YearTag, 2)
        Case "12"
            ActiveMonth = "DEC" & Right(YearTag, 2)
    End Select
    ActiveWorkbook.Close SaveChanges:=True

    Dim MyFolder As String
    Dim Qty As Double
    Dim SumQty As Double
    Dim Found As Integer
    Dim SumFound As Integer

    MyFolder = ActiveWorkbook.Path & "\bill\"

    If Dir((MyFolder & "\" & YearTag & "\Bill_Summary_Report_" & ActiveMonth & ".xls")) <> "" Then

        Application.Workbooks.Open (MyFolder & "\" & YearTag & "\Bill_Summary_Report_" & ActiveMonth & ".xls")
        Worksheets("Cement").Select

        'Find contract coordinates
        x = 1
        Do Until Cells(x, 1).Value = "Sno"
            x = x + 1
        Loop

        y = 1
        Do Until Cells(x, y).Value = "Contract"
            y = y + 1
        Loop

        'Find Qty coordinates
        p = 1
        Do Until Cells(p, 1).Value = "Product"
            p = p + 1
        Loop

        q = 1
        Do Until Cells(p, q).Value = "C Qty"
            q = q + 1
        Loop

        'Determine the quantity delivered for the month
        'this area is proned with problems since one spacing could distort the data
        'may want to manual check for multiple occurences of contract no!
        n = 1
        SumFound = 0
        SumQty = 0
        Do Until IsEmpty(Cells(17 + n, y).Value)
            If ContractNo = Cells(17 + n, y).Value Then
                Found = 1
                Qty = Cells(19 + n, q).Value
            Else
                Found = 0
                Qty = 0

            End If

        SumFound = SumFound + Found
        SumQty = SumQty + Qty
        n = n + 10
        Loop

        ActiveWorkbook.Close

    Else

        SumQty = 0

    End If

    Application.Workbooks.Open (OutputPath)
    Cells(j + 2, 7 + m).Value = SumQty
    ActiveWorkbook.Close SaveChanges:=True
    'MsgBox "m: " & m & vbNewLine & "yr: " & YearTag & vbNewLine & "j: " & j

    Next m

Next j

End Sub