|
本帖最后由 hhl3288 于 2013-6-29 09:41 编辑
楼上的两位的办法都试过了,大灰狼1976 的办法总是报错,sheet1 的办法没反应。不知道怎么回事。代码是:
Private Sub Worksheet_Change(ByVal Target As Range)
'《自动计算总金额》
Application.ScreenUpdating = False
If Not Application.Intersect(Target, Union(Range("C3:d65536"), Range("j3:j65536"))) Is Nothing Then
a = Target.Row
If Range("C" & a).Value <> "" And Range("D" & a).Value <> "" Then
Range("E" & a) = Range("C" & a).Value * Range("D" & a).Value
Cells(a, 10).Select
Else
Range("E" & a) = ""
End If
If Range("C" & a).Value <> "" And Range("D" & a).Value <> "" And Range("j" & a).Value <> "" Then
Range("k" & a) = (Range("d" & a).Value - Range("j" & a).Value) * Range("c" & a).Value
Range("l" & a) = 1 - Range("j" & a).Value / Range("d" & a).Value
Else
Range("k" & a) = ""
Range("l" & a) = ""
End If
End If
If Not Application.Intersect(Target, Range("g3:g65536")) Is Nothing Then
a = Target.Row
If Range("g" & a).Value <> "" Then
Range("h" & a) = Application.WorksheetFunction.Sum(Range(Cells(3, 5), Cells(a, 5))) - Application.WorksheetFunction.Sum(Range(Cells(3, 7), Cells(a, 7)))
Else
Range("h" & a) = ""
End If
End If
'《审核后保护行》
ActiveSheet.Unprotect
Cells.Locked = False
For i = 3 To [a65536].End(xlUp).Row
If Cells(i, 9) = "已审" Then
Range(Cells(i, 1), Cells(i, 8)).Locked = True
Range(Cells(i, 10), Cells(i, 12)).Locked = True
Else
Range(Cells(i, 1), Cells(i, 8)).Locked = False
Range(Cells(i, 10), Cells(i, 12)).Locked = False
End If
Next
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
ActiveSheet.EnableSelection = xlUnlockedCells
'《审核列默认输入待审》
If Target.Count > 1 Then Exit Sub '异动单元格大于1跳出程序
If Target.Column <> 1 Then Exit Sub '异动非B栏单元格跳出程序
If Target = "" Then '异动B单元格空值
Cells(Target.Row, 9) = ""
Else
Cells(Target.Row, 9) = "待审"
' Cells(Target.Row, 11) = ActiveSheet.Name
End If
Application.ScreenUpdating = True
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'防止看错行
If Target.Row >= 3 Then
If Not (Application.CutCopyMode >= xlCopy) Then
ActiveSheet.Unprotect
Cells.Interior.ColorIndex = xlNone
Cells.Font.Bold = False
Range(Cells(Target.Row, 1), Cells(Target.Row, 12)).Interior.ColorIndex = 36
Range(Cells(Target.Row, 1), Cells(Target.Row, 16)).Font.Bold = True
' Columns(Target.Column).Interior.ColorIndex = 35
Cells(Target.Row, Target.Column).Interior.ColorIndex = 44
End If
End If
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
|
|