標題:
[發問]
worksheet 事件導致無法複製貼上
[打印本頁]
作者:
s13030029
時間:
2019-11-19 15:05
標題:
worksheet 事件導致無法複製貼上
我的2個工作表都有如下一樣的程式碼,不知道是哪裡有問題導致我要在兩個工作表之間無法進行複製貼上,我有把程式註解掉試,結果是可以複製貼上的
不知道有沒有人知道是哪裡出了問題???
我也有查到Application.EnableEvents = False,Application.EnableEvents = True,的用法,但會變成我的程式碼沒辦法用。
希望有高手能幫幫忙@@
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
If [A37].Value <> "" Then
Range("C39").Value = Range("C3").Value
Range("I39").Value = Range("I3").Value
Range("C42").Value = Range("C6").Value
Range("C43").Value = Range("C7").Value
Range("I41").Value = Range("I5").Value
Range("I42").Value = Range("I6").Value
Range("I43").Value = Range("I7").Value
Range("I44").Value = Range("I8").Value
Range("C72").Value = Range("C36").Value
Range("B69").Value = Range("B33").Value
End If
If [F11] = "" Then Exit Sub
If [F11] <> "" Then Application.MoveAfterReturnDirection = xlToRight
If Target.Column = 11 Then Target(2, -4).Select
End Sub
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim SelRng As Range
Set SelRng = Application.Intersect([F11:J31,F47:J67], Target)
If SelRng Is Nothing Then Exit Sub
If SelRng.Count > 1 Then Exit Sub
If SelRng & "" = "0" Then
SelRng = "OK"
ElseIf SelRng & "" = "." Then
SelRng = "N/A"
End If
End Sub
複製代碼
[attach]31426[/attach]
作者:
s13030029
時間:
2019-11-19 15:58
版本是 excel 2007
作者:
s13030029
時間:
2019-11-19 16:58
已解決~~
' Application.EnableEvents = False 停止觸發事件
' Application.EnableEvents = True 重新啟動事件
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Sel As Range
Set Sel = Application.Intersect([K:K], Target)
If Sel Is Nothing Then GoTo ena
If Sel.Count > 1 Then GoTo ena
If [A37].Value <> "" Then
Range("C39").Value = Range("C3").Value
Range("I39").Value = Range("I3").Value
Range("C42").Value = Range("C6").Value
Range("C43").Value = Range("C7").Value
Range("I41").Value = Range("I5").Value
Range("I42").Value = Range("I6").Value
Range("I43").Value = Range("I7").Value
Range("I44").Value = Range("I8").Value
Range("C72").Value = Range("C36").Value
Range("B69").Value = Range("B33").Value
End If
If [F11] = "" Then Exit Sub
If [F11] <> "" Then Application.MoveAfterReturnDirection = xlToRight
If Sel.Column = 11 Then
Application.EnableEvents = False
Target(2, -4).Select
End If
ena:
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim SelRng As Range
Set SelRng = Application.Intersect([F11:J31,F47:J67], Target)
If SelRng Is Nothing Then GoTo en
If SelRng.Count > 1 Then GoTo en
If SelRng & "" = "0" Then
SelRng = "OK"
ElseIf SelRng & "" = "." Then
SelRng = "N/A"
End If
en:
Application.EnableEvents = True
End Sub
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)