Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.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 我一直在尝试此代码,但由于无法工作而退出。有人能建议改正吗?_Excel_Vba - Fatal编程技术网

Excel 我一直在尝试此代码,但由于无法工作而退出。有人能建议改正吗?

Excel 我一直在尝试此代码,但由于无法工作而退出。有人能建议改正吗?,excel,vba,Excel,Vba,我有以下代码并退出,因为它不在此工作 p = Application.WorksheetFunction.Match(SLA_scenarios.Cells(i + 1, 372 - j).Value, (Capacities_sheet.Range(Capacities_sheet.Cells(1, 76), Capacities_sheet.Cells(1, 147))), False) For m = 1 To p If TempBestload >= (SLA_scena

我有以下代码并退出,因为它不在此工作

p = Application.WorksheetFunction.Match(SLA_scenarios.Cells(i + 1, 372 - j).Value, (Capacities_sheet.Range(Capacities_sheet.Cells(1, 76), Capacities_sheet.Cells(1, 147))), False)

For m = 1 To p
    If TempBestload >= (SLA_scenarios.Cells(i + 1, 78).Value * 0.9) Then
        Exit For
        Bestslot.Cells(1 + i, 6).Value = SLA_scenarios.Cells(i + 1, 372 - j).Value
    Else:
        TempBestslot2 = Application.WorksheetFunction.VLookup(SLA_scenarios.Cells(i + 1, 2).Value, Capacities_sheet.Range("A:EQ"), (Application.Match(SLA_scenarios.Cells(i + 1, 372 - j).Value, (Capacities_sheet.Range(Capacities_sheet.Cells(1, 1), Capacities_sheet.Cells(1, 147))), False) - m), False)

        'If capacity is not zero for previous slot
        If TempBestslot2 <> 0 Then
            TempBestload = TempBestload + TempBestslot2
            Bestslot.Cells(4, 8 + a).Value = TempBestload
            Bestslot.Cells(5, 8 + a).Value = SLA_scenarios.Cells(i + 1, 372 - j).Value
            k = k + 1
            Bestslot.Cells(2, 8 + a).Value = Application.WorksheetFunction.Match(SLA_scenarios.Cells(i + 1, 2).Value, (Capacities_sheet.Range(Capacities_sheet.Cells(1, 1), Capacities_sheet.Cells(37, 1))), False)
            Bestslot.Cells(3, 8 + a).Value = 75 + Application.WorksheetFunction.Match((SLA_scenarios.Cells(1 + i, 372 - j).Value), (Capacities_sheet.Range(Capacities_sheet.Cells(1, 76), Capacities_sheet.Cells(1, 147))), False) - m + 1

        'If capacity is zero then check the next best slot
        Else:
            GoTo NextIteration2
            k = 0
        End If
    End If
Next m
p=Application.WorksheetFunction.Match(SLA_场景.单元格(i+1372-j).Value,(容量表范围(容量表单元格(1,76),容量表单元格(1,147)),False)
对于m=1到p
如果TempBestload>=(SLA_.Cells(i+1,78).Value*0.9),则
退出
Bestslot.Cells(1+i,6).Value=SLA_场景.Cells(i+1372-j).Value
其他:
TempBestslot2=Application.WorksheetFunction.VLookup(SLA_场景.单元格(i+1,2).值,容量表.范围(“A:EQ”),(Application.Match(SLA_场景.单元格(i+1372-j).值,(容量表.范围(容量表.单元格(1,1),容量表.单元格(1147)),False)-m,False)
'如果上一个插槽的容量不是零
如果TempBestslot2为0,则
TempBestload=TempBestload+TempBestslot2
Bestslot.Cells(4,8+a).Value=TempBestload
Bestslot.Cells(5,8+a).Value=SLA_场景.Cells(i+1372-j).Value
k=k+1
Bestslot.Cells(2,8+a).Value=Application.WorksheetFunction.Match(SLA\u场景.Cells(i+1,2).Value,(容量表范围(容量表.单元格(1,1),容量表.单元格(37,1)),False)
Bestslot.Cells(3,8+a).Value=75+应用程序.WorksheetFunction.Match((SLA\u场景.Cells(1+i,372-j).Value),(容量表范围(容量表.Cells(1,76),容量表.Cells(1,147))),False)-m+1
'如果容量为零,则检查下一个最佳插槽
其他:
转到下一站2
k=0
如果结束
如果结束
下一个m

您有两行永远不会运行的代码

...
If TempBestload >= (SLA_scenarios.Cells(i + 1, 78).Value * 0.9) Then
    'This next line exits the For m = 1 To p loop entirely. The next code
    'that runs is under the Next m code line
    Exit For
    'This next line will never be run.
    Bestslot.Cells(1 + i, 6).Value = SLA_scenarios.Cells(i + 1, 372 - j).Value
Else:
...

...
    Else:
        'This next line moves execution to the NextIteration2 label. The next line
        'of code that executes is under the NextIteration2: label.
        GoTo NextIteration2
        'This next line will never be run.
        k = 0
    End If
...
如果希望执行这些代码行,请将它们移到重定向代码行上方。e、 g.将
k=0
移到上面的
GoTo NextIteration2

另外,我看不出
中的
有什么意义。
用于将两行代码放在同一行上。它通常由不喜欢使用垂直空间的程序员使用,因此他们将普通(但相关的)代码行分组到一行上。e、 g

dim i as long: i = 10

只需删除
并使用
Else

哪一行不起作用?不起作用并不是一个真正有用的描述。此外,
Bestslot.Cells(1+i,6).Value=SLA_scenarios.Cells(i+1372-j).Value
Exit For
之后的值永远无法达到。如果这是您的问题,那么您需要在该行之后放置
Exit For