首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行时错误'1004':对象_worksheet的方法范围失败EPM BPC VBA

运行时错误'1004':对象_worksheet的方法范围失败EPM BPC VBA
EN

Stack Overflow用户
提问于 2017-10-27 04:36:45
回答 2查看 161关注 0票数 0

我正在使用非常基本的VBA,但在我们刚刚在SAP\BPC上进行了SP升级之后,我正在尝试修复其他人的代码。请找到下面的代码:

错误部分:

代码语言:javascript
复制
For Each CurCell In Input_Sheet.Range(Input_Sheet.Range("SPREAD_COLUMN"), Input_Sheet.Range("SPREAD_COLUMN").Offset(Input_Sheet.Cells.SpecialCells(xlCellTypeLastCell).Row, 0))

代码:

代码语言:javascript
复制
Private Function AFTER_REFRESH()
    ' Apply the in-cell drop-downs (validations) for the spreads

    Dim CurCell As Range

    Application.EnableEvents = False
    Application.ScreenUpdating = False

    UnProtect_Sheet

    For Each CurCell In Input_Sheet.Range(Input_Sheet.Range("SPREAD_COLUMN"), Input_Sheet.Range("SPREAD_COLUMN").Offset(Input_Sheet.Cells.SpecialCells(xlCellTypeLastCell).Row, 0))
        If Not CurCell.Font.Bold Then
            With CurCell.Validation ' apply validation (drop-down) to spread column
                .Delete
                .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=SPREAD_METHODS"
                .InCellDropdown = True
            End With

        End If
    Next


    If LockWorkbook Then
        Protect_Sheet
    End If

    Application.EnableEvents = True
    Application.ScreenUpdating = True

End Function

谢谢你的帮助,并致以亲切的问候。

EN

回答 2

Stack Overflow用户

发布于 2017-10-27 04:56:51

从“即时”窗口(Ctrl+G)中,将Input_Sheet.Range(Input_Sheet.Range("SPREAD_COLUMN"), Input_Sheet.Range("SPREAD_COLUMN").Offset(Input_Sheet.Cells.SpecialCells(xlCellTypeLastCell).Row, 0))行拆分为其组件,并查看发生错误的位置。

代码语言:javascript
复制
?Input_Sheet.Range("SPREAD_COLUMN").Address

然后

代码语言:javascript
复制
?Input_Sheet.Cells.SpecialCells(xlCellTypeLastCell).Row

然后

代码语言:javascript
复制
Input_Sheet.Range("SPREAD_COLUMN").Offset(Input_Sheet.Cells.SpecialCells(xlCellTypeLastCell).Row, 0)

上面的其中一个将失败,并将使您走上解决问题的轨道。例如,也许Input_Sheet上没有"SPREAD_COLUMN“范围;也许最后使用的行足够大,导致偏移量超过1'048'576行的限制;也许Input_Sheet.Range("SPREAD_COLUMN")是一整列,不能垂直偏移;等等。

票数 0
EN

Stack Overflow用户

发布于 2017-10-27 05:03:47

将代码更改为Sub而不是Function可能更好,因为它执行过程而不返回值。

您是否在过程外声明了input_sheet?

代码语言:javascript
复制
Option explicit

Private Sub AFTER_REFRESH()
'Apply the in-cell drop-downs (validations) for the spreads

Application.EnableEvents = False
Application.ScreenUpdating = False 

UnProtect_Sheet

If not (Input_Sheet is nothing) then

Dim CurCell As Range

On error resume next
Set CurCell = input_sheet.range("SPREAD_COLUMN")
ON error GOTO 0

If not (curcell is nothing) then

For Each CurCell In Input_sheet.Range(Input_sheet.range("SPREAD_COLUMN"), Input_sheet.Range("SPREAD_COLUMN").Offset(Input_Sheet.Cells.SpecialCells(xlCellTypeLastCell).Row, 0)

If Not CurCell.Font.Bold Then

With CurCell.Validation ' apply validation (drop-down) to spread column 
.Delete 
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=SPREAD_METHODS"
.InCellDropdown = True
End With

End If
Next cell
Else
Msgbox("Input_Sheet exists, but does not contain the range SPREAD_COLUMN.")
End if

    Else
    Msgbox("Input_Sheet does not exist")
    End if

If LockWorkbook Then 
Protect_Sheet
End If

Application.EnableEvents = True
Application.ScreenUpdating= True

End Function
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46963366

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档