如何提高vba执行效率,高手帮看下代码,执行有点卡顿
PrivateSubWorksheet_Change(ByValTargetAsRange)DimiRow,iColAsStringIfTarget.Column=2Th...
Private Sub Worksheet_Change(ByVal Target As Range)
Dim iRow, iCol As String
If Target.Column = 2 Then
Application.ScreenUpdating = False
r = Target.Row
For c1 = 5 To 25
Cells(3, c1).Copy
Cells(r, c1).PasteSpecial
Next c1
Application.CutCopyMode = False
Cells(r, 3).Select
iRow = Target.Row
iCol = Target.Column
If Target.Count > 1 Then Exit Sub
If iRow >= 2 And iCol = 2 And Target <> "" Then
Target.Offset(0, -1) = Now()
ElseIf iRow >= 2 And iCol = 2 And Target = "" Then
Cells(iRow, iCol + 9) = ""
Cells(iRow, iCol + 10) = ""
Cells(iRow, iCol - 1) = ""
End If
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 5 Then
Cells(Target.Row + 1, 2).Activate
End If
End Sub 展开
Dim iRow, iCol As String
If Target.Column = 2 Then
Application.ScreenUpdating = False
r = Target.Row
For c1 = 5 To 25
Cells(3, c1).Copy
Cells(r, c1).PasteSpecial
Next c1
Application.CutCopyMode = False
Cells(r, 3).Select
iRow = Target.Row
iCol = Target.Column
If Target.Count > 1 Then Exit Sub
If iRow >= 2 And iCol = 2 And Target <> "" Then
Target.Offset(0, -1) = Now()
ElseIf iRow >= 2 And iCol = 2 And Target = "" Then
Cells(iRow, iCol + 9) = ""
Cells(iRow, iCol + 10) = ""
Cells(iRow, iCol - 1) = ""
End If
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 5 Then
Cells(Target.Row + 1, 2).Activate
End If
End Sub 展开
展开全部
没说你要实现的效果,只能这样了。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim iRow As Long, iCol As Long
If Target.Column = 2 And Target.Count = 1 Then
On Error Resume Next
Application.ScreenUpdating = False
Application.EnableEvents = False
r = Target.Row
Cells(3, 5).Resize(, 21).Copy Cells(r, 5) '5-25
Cells(r, 3).Select
iRow = Target.Row
iCol = Target.Column
If iRow >= 2 And Target <> "" Then
Target.Offset(0, -1) = Now()
ElseIf iRow >= 2 And Target = "" Then
Cells(iRow, iCol + 9) = ""
Cells(iRow, iCol + 10) = ""
Cells(iRow, iCol - 1) = ""
End If
Application.EnableEvents = True
End If
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询