[英]method range of object _global failed in named range
我在這里看到過同樣的問題,但無法解決...請幫助。 Hai先生,目前我正在將2003格式中的所有excel宏轉移到2007年。我面臨的問題是_global對象的方法范圍失敗,請提供一個解決方案。
請參閱代碼... range(“ Phasewt”)沒有更新...。此工作簿中的任何命名范圍都沒有更新,到處都顯示錯誤1004:Iam正在使用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
感謝您的關注。
“對象_global失敗”錯誤顯示,因為Excel無法找到工作簿中給定的范圍內,所以一定要確保你有范圍"ReleaseTo"
, "PhaseWt"
, "PhaseArea"
在該文件中的某處定義。
編輯:嘗試從此調用您的代碼:
Sub test()
With ActiveSheet
.Range("B13").Name = "jobno"
.Range("D13").Name = "bldgno"
.Range("F13").Name = "phaseno"
.Range("D15").Name = "project"
.Range("D16").Name = "Client"
.Range("J15").Name = "location"
.Range("K12").Name = "PhaseWt"
.Range("K13").Name = "PhaseArea"
End With
Call FormatRowsAndSum(1, 10)
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.