我正在使用非常基本的VBA,但是在我们刚刚在SAP \ BPC(EPM加载项)上进行SP升级之后,我正在尝试修复其他人的代码。 请找到以下代码:
错误部分:
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))
代码:
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
感谢您的亲切问候。
答案 0 :(得分:0)
在立即窗口(Ctrl + G)中,将Input_Sheet.Range(Input_Sheet.Range("SPREAD_COLUMN"), Input_Sheet.Range("SPREAD_COLUMN").Offset(Input_Sheet.Cells.SpecialCells(xlCellTypeLastCell).Row, 0))
行分解为其组件,并查看错误发生的位置。
待办事项
?Input_Sheet.Range("SPREAD_COLUMN").Address
然后
?Input_Sheet.Cells.SpecialCells(xlCellTypeLastCell).Row
然后
Input_Sheet.Range("SPREAD_COLUMN").Offset(Input_Sheet.Cells.SpecialCells(xlCellTypeLastCell).Row, 0)
上述其中一项将失败,并将使您按计划解决问题。例如,也许没有" SPREAD_COLUMN" Input_Sheet上的范围;也许最后使用的行足够大,导致偏移超过1> 048' 576行限制;也许Input_Sheet.Range(" SPREAD_COLUMN")是一个不能垂直偏移的整列;等
答案 1 :(得分:0)
最好将代码更改为Sub而不是Function,因为它执行过程并且不返回值。
您是否在程序之外声明了input_sheet?
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