我正在使用非常基本的VBA,但在我们刚刚在SAP\BPC上进行了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谢谢你的帮助,并致以亲切的问候。
发布于 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))行拆分为其组件,并查看发生错误的位置。
做
?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)上面的其中一个将失败,并将使您走上解决问题的轨道。例如,也许Input_Sheet上没有"SPREAD_COLUMN“范围;也许最后使用的行足够大,导致偏移量超过1'048'576行的限制;也许Input_Sheet.Range("SPREAD_COLUMN")是一整列,不能垂直偏移;等等。
发布于 2017-10-27 05:03:47
将代码更改为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 Functionhttps://stackoverflow.com/questions/46963366
复制相似问题