对象_global的方法范围在命名范围

时间:2017-01-24 12:16:49

标签: excel excel-vba vba

我在这里看到了同样的问题,但无法解决......请帮忙。 Hai先生目前我在一个项目中将2003年格式的所有excel宏转移到2007年。我面临的问题是对象的方法范围_global失败 请给我一个解决方案。

请参阅代码......范围(“Phasewt”)不更新.... 本工作簿中没有任何命名范围正在更新,无处不在显示错误1004: 我现在使用Office 2007。

Private Sub FormatRowsAndSum(ByVal TotRows As Integer, StartRow As Integer)
    Dim rngFormat As Range

        'adds formatting
    If TotRows > 2 Then
        Set rngFormat = Range(Cells(StartRow + 2, 2), Cells(TotRows + StartRow + 1, 8))
        'Range("B11:H11").Select
        Range(Cells(StartRow + 1, 2), Cells(StartRow + 1, 8)).Select

        Selection.Copy
        rngFormat.Select
        Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False

        'adds formula
        Set rngFormat = Range(Cells(StartRow + 2, 11), Cells(TotRows + StartRow, 12))
        'Range("K11:L11").Select
        Range(Cells(StartRow + 1, 11), Cells(StartRow + 1, 12)).Select

        Selection.Copy
        rngFormat.Select
        Selection.PasteSpecial Paste:=xlPasteFormulas, Operation:=xlNone, _
            SkipBlanks:=False, Transpose:=False

        Application.CutCopyMode = False

    End If

    ActiveSheet.PageSetup.FitToPagesWide = 1

    Cells(TotRows + StartRow + 1, 2) = "TOTALS"
    Cells(TotRows + StartRow + 1, 2).Font.Bold = True
    Cells(TotRows + StartRow + 1, 2).RowHeight = 20

    Range(Cells(TotRows + StartRow + 1, 2), Cells(TotRows + StartRow + 1, 8)).Select
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
    End With


    'writes total weight
    With Cells(TotRows + StartRow + 1, 6)
        .Value = "=SUM(K" & StartRow & ":K" & TotRows + StartRow & ")"
        .Font.Bold = True
        .NumberFormat = "#,##0.00"
    End With
    If Range("ReleaseTo") <> "STR" Then
        Range("PhaseWt") = Cells(TotRows + StartRow + 1, 6) ' writes total wt in cover page
    End If

   'writes total cladding Area
    With Cells(TotRows + StartRow + 1, 7)
        .Value = "=SUM(L" & StartRow & ":L" & TotRows + StartRow & ")"
        .Font.Bold = True
        .NumberFormat = "#,##0.00"
    End With
    If Cells(TotRows + StartRow + 1, 7) > 0 Then
        If Range("ReleaseTo") <> "STR" Then
            Range("PhaseArea") = Cells(TotRows + StartRow + 1, 7) ' writes total Area in cover page
        End If
    End If

    'writes total quantity
    With Cells(TotRows + StartRow + 1, 3)
        .Value = "=SUM(C" & StartRow & ":C" & TotRows + StartRow & ")"
        .Font.Bold = True
        .NumberFormat = "#,##0"
    End With

    Range("B4").Select
End Sub

感谢您的关注。

1 个答案:

答案 0 :(得分:0)

&#34;对象_global失败&#34;显示的错误是因为Excel无法在工作簿中找到给定的范围,因此请确保您在文件的某个位置定义了范围mHelper"ReleaseTo""PhaseWt"

编辑:尝试从此处调用您的代码:

"PhaseArea"