2017-06-05 155 views
-1

我有一個宏從命名範圍中刪除一行。
按下按鈕運行該宏後,我無法編輯單元格了。
不在該範圍內,也不在受保護的工作表中的任何可編輯單元格中。
似乎具有相同代碼的工作簿在Excel 2010中也不起作用。
這是我的宏:
單擊Excel按鈕後無法編輯單元格的值

Sub DeleteParameterRow(ByVal tCell As Range) 

    '''this procedure delete a row from one of the parameters lists 
    On Error GoTo ErrHandler 

    Application.EnableEvents = False 
    Application.DisplayAlerts = False 

    Dim iRowToDelete As Integer 

    Call Unprotect_All() 

    If IsPartOfRange(tCell, NamedRange("Param_ParametersList"), False) Then 

     tCell.Delete Shift:=xlUp 

    Else 

     MsgBox("Please select one of the parameters list", vbInformation, "Error") 

    End If 

EndProc: 
    Call Protect_All() 
    Application.DisplayAlerts = True 
    Application.EnableEvents = True 
    Exit Sub 

ErrHandler: 
    MsgBox(Err.Description, vbCritical, Err.Number) 
    GoTo EndProc 

End Sub 


Function IsPartOfRange(ByVal rSearchRange As Range, ByVal rSearchInRange As Range, ByVal bIsEntireRange As Boolean) As Boolean 
    '''this function gets a small range, a big range and if it is supposed to be the entire range, and check 
    '''if the smaller range is part of the bigger one, and if it is the entire range 
    IsPartOfRange = False 

    If Not Intersect(rSearchRange, rSearchInRange) Is Nothing Then 

     If bIsEntireRange = True Then 

      If rSearchRange.Address = rSearchInRange.MergeArea.Address Then IsPartOfRange = True 

     Else 

      IsPartOfRange = True 

     End If 

    End If 

End Function 
+0

請提供一些代碼供我們查看,看看我們是否可以重現。你現在在運行什麼版本的Excel?你真正的問題是什麼? –

+0

是否在宏的開始處禁用事件,然後不在最後重新啓用它們?獲得更多的上下文(和代碼)以幫助我們會很有幫助。 – sous2817

+2

尋求調試幫助的問題(「爲什麼這個代碼不工作?」)必須包含所需的行爲,特定的問題或錯誤以及在問題本身中重現問題所需的最短代碼。沒有明確問題陳述的問題對其他讀者無益。 –

回答

0

見我最後的評論是我提到這似乎是一種「刷新」的問題。
代碼運行後,在Excel中堆疊了一些可防止編輯的東西。 (No way to report bugs to MS... :(
要以編程方式強制執行「刷新」,我發現清除任意單元格的內容是有用的。
因此添加行tCell.ClearContents befor EndProc:做了trik。

+0

我重新打開答案,因爲我發現在另一個工作簿中,它不工作:( –

相關問題