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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.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 ,包括未声明的变量、未使用的变量、未分配的变量、从未分配使用的变量、声明为整数的行号、隐式的ActiveWorkbook引用……这段代码需要很多爱! Sub automated_gr_lookup() Dim st As Long Dim _Excel_Vba_Runtime Error - Fatal编程技术网

Excel ,包括未声明的变量、未使用的变量、未分配的变量、从未分配使用的变量、声明为整数的行号、隐式的ActiveWorkbook引用……这段代码需要很多爱! Sub automated_gr_lookup() Dim st As Long Dim

Excel ,包括未声明的变量、未使用的变量、未分配的变量、从未分配使用的变量、声明为整数的行号、隐式的ActiveWorkbook引用……这段代码需要很多爱! Sub automated_gr_lookup() Dim st As Long Dim ,excel,vba,runtime-error,Excel,Vba,Runtime Error,,包括未声明的变量、未使用的变量、未分配的变量、从未分配使用的变量、声明为整数的行号、隐式的ActiveWorkbook引用……这段代码需要很多爱! Sub automated_gr_lookup() Dim st As Long Dim en As Long Dim c1 As Long Dim c2 As Long Dim iRowAsset As Integer Dim table As Range Dim tmpRiskID As

,包括未声明的变量、未使用的变量、未分配的变量、从未分配使用的变量、声明为整数的行号、隐式的
ActiveWorkbook
引用……这段代码需要很多爱!
Sub automated_gr_lookup()
    Dim st As Long
    Dim en As Long
    Dim c1 As Long
    Dim c2 As Long
    Dim iRowAsset As Integer
    Dim table As Range
    Dim tmpRiskID As Variant

    Sheets("Geotechnical Risk Register").Select

    Application.ScreenUpdating = False

    Set assetTbl = Application.Range("M002_") 'Asset table = DES M002
    Set riskTbl = Application.Range("geotechRisks") 'GRR
    Set compiledTbl = Application.Range("CompiledM002") 'Output for M002


    For iRowRisk = 1 To riskTbl.Rows.Count 'loop through risks
        tmpRiskID = riskTbl.Row.Range("Ref No. ID") 'Temporary risk as it gets overridden


        'if assets chainage match risk iRowRisk (4 conditions)
        If (en > c1 And en < c2) Or (st > c1 And en < c2) Or (st > c1 And st < c2) Or (st < c1 And en > c2) Then
            'copy asset row
            assetTbl.Rows(iRowAsset).Copy
            'paste row in compiled
            compiledTbl.Rows(xlEndRow).PasteSpecial xlPasteValues
            'paste risk id in last column of that row
            compiledTbl.Cells(xlEndRow, ColumnH).Value = tmpRiskID
        End If
    Next iRowRisk

End Sub
Sheets("Geotechnical Risk Register").Select
ThisWorkbook.Worksheets("Geotechnical Risk Register").Select
Dim ws As Worksheet
Set ws = ThisWorkbook.Worksheets("Geotechnical Risk Register")
Set assetTbl = Application.Range("M002_")
Dim assetTbl As ListObject
Set assetTbl = GeotechRiskRegisterSheet.ListObjects("M002_")
Set riskTbl = Application.Range("geotechRisks") 'GRR
Set compiledTbl = Application.Range("CompiledM002") 'Output for M002
Dim riskTbl As ListObject
Set riskTbl = GeotechRisksSheet.ListObjects("geotechRisks")

Dim compiledTbl As ListObject
Set compiledTbl = CompiledSheet.ListObjects("CompiledM002")
For iRowRisk = 1 To riskTbl.Rows.Count 'loop through risks
Dim currentRow As ListRow
For Each currentRow In riskTbl.ListRows
tmpRiskID = riskTbl.Row.Range("Ref No. ID") 'Temporary risk as it gets overridden
tmpRiskID = riskTbl.Cells(iRowRisk, 12).Value
Dim refIDColumn As Long
refIDColumn = riskTbl.ListColumns("Ref No. ID").Index

tmpRiskID = currentRow.Range.Cells(ColumnIndex:=refIDColumn).Value
    'if assets chainage match risk iRowRisk (4 conditions)
    If (en > c1 And en < c2) Or (st > c1 And en < c2) Or (st > c1 And st < c2) Or (st < c1 And en > c2) Then
        'copy asset row
        assetTbl.Rows(iRowAsset).Copy
        'paste row in compiled
        compiledTbl.Rows(xlEndRow).PasteSpecial xlPasteValues
        'paste risk id in last column of that row
        compiledTbl.Cells(xlEndRow, ColumnH).Value = tmpRiskID
    With compiledTbl.ListRows.Add
        .Range.Value = currentRow.Range.Value
        .Range.Cells(ColumnIndex:=compiledRiskIdColumn).Value = tmpRiskID
    End With
Dim compiledRiskIdColumn As Long
compiledRiskIdColumn = compieldTbl.ListColumns("Risk ID").Index '<~ verify column title