请问哪位会把下列的宏加入到EXCEL..要详解..一步一步来.

来源:百度知道 编辑:UC知道 时间:2024/06/30 16:46:07
Dim ValueBefore
Private Sub Workbook_Open()
ValueBefore = ActiveCell.Value
End Sub
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim Rng As Range
Application.EnableEvents = False '禁止触发事件
Set Rng = Range("a1:c5,e1:f5") '你需要的单元格区域
If Intersect(Target, Rng) Is Nothing Then '选择单元不在区内
Application.EnableEvents = True '允许触发事件
Exit Sub '就退出
End If
On Error GoTo 100
If Target.Value <> ValueBefore Then
Target.Value = Target.Value * 5
Application.ScreenUpdating = True
End If
100: '错误处理
If Err.Number = 13 Then
End If
Application.EnableEvents = True '允许触发事件
End Sub
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
ValueBefore = Target.Value
End Sub
试了不好用..缺少END SUB
谁试试..别人做就可以为什么 我不行

这个很简单:
1、打开你要运行的EXCEL文件
2、ALT + F11,打开VBE窗口
3、在左侧工程管理器窗口中双击THISWORKBOOK,进入代码窗口
4、粘贴以下代码:
Dim ValueBefore
Private Sub Workbook_Open()
ValueBefore = ActiveCell.Value
End Sub

5、在左侧工程管理器窗口中双击你需要运行的工作表名称sheet1(..),在代码窗口中上方下拉列表中选择:通用选为:worksheet;右侧改为change
粘贴以下代码:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim Rng As Range
Application.EnableEvents = False '禁止触发事件
Set Rng = Range("a1:c5,e1:f5") '你需要的单元格区域
If Intersect(Target, Rng) Is Nothing Then '选择单元不在区内
Application.EnableEvents = True '允许触发事件
Exit Sub '就退出
End If
On Error GoTo 100
If Target.Value <> ValueBefore Then
Target.Value = Target.Value * 5
Application.ScreenUpdating = True
End If
100: '错误处理
If Err.Number = 13 Then
End If
Application.EnableEvents = True '允许触发事件
End Sub

6、把上方右侧下拉