每當我嘗試突出顯示D列時,都會收到「運行時錯誤13」。當我點擊調試時,它從代碼If Target.Value = "Closed" Or Target.Value = "Closed" Then
中突出顯示了這一塊。我將不勝感激關於如何解決此問題的任何建議。突出顯示整行時的運行時錯誤13
編輯*
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim wsd As Worksheet
Dim wsc As Worksheet
Application.ScreenUpdating = False
Set wsd = Sheets("Pipeline")
Set wsc = Sheets("Closed")
If Not Intersect(Target, Range("D6:D65536")) Is Nothing Then
If Target.Value = "Closed" Or Target.Value = "Closed" Then
erow = Target.Row
MsgBox "Moved to Closed"
numberofrow = wsc.Range("A65536").End(xlUp).Row
For i = 1 To numberofrow
If wsd.Cells(erow, 1) = wsc.Cells(i, 1) Then
Exit Sub
End If
Next
wsd.Range("A" & erow & ":A" & erow).EntireRow.Copy wsc.Range("A" & numberofrow + 1)
With Target.Parent
Union(.Range(.Cells(Target.Row, "A"), .Cells(Target.Row, "V")), _
.Range(.Cells(Target.Row, "Y"), .Cells(Target.Row, .Columns.Count))).ClearContents
`enter code here`End With
wsc.Activate
ActiveSheet.Range("A2:D" & numberofrow + 1).Select
ActiveWorkbook.Worksheets("Closed").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Closed").Sort.SortFields.Add Key:=Range("C2:C" & numberofrow + 1), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Closed").Sort
.SetRange Range("A2:D" & numberofrow + 1)
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
wsd.Activate
End If
End If
End Sub
我不得不爲了得到這個工作,這就是爲什麼它是很醜陋的拼湊一些東西放在一起。我無法弄清楚在哪裏放置警戒條款。到目前爲止,這已經適用於我需要的功能(除運行時錯誤外),根據輸入到D列的銷售階段將帳戶轉移到單獨的工作表。再次感謝所有幫助。
在您的事件處理程序中添加一個警戒子句:'如果Target.Cells.Count = 1'。 – Comintern
另外,爲什麼有相同的情況兩次? – BruceWayne
您需要改善您的Worksheet_SelectionChange事件宏,以便它不會在每次您在工作表上執行任何操作時觸發。 – Jeeped