我有一个包含多个工作表的Excel 2013工作簿。在一张纸上,我有一个宏,显示单元格E7:E999中的公式。除了2件事以外,它的工作正常。
这是我目前拥有的宏。它做我想要的,它不会自动完成,它可以在任何工作表上运行。我是Excel中的VBA新手,所以如果你能给出一些最有帮助的答案的详细信息。
Sub ShowFormulas()
Dim DQ As String, mesage As String
Dim rng As Range, r As Range
DQ = Chr(34)
Set rng = Range("E7:E999").Cells.SpecialCells(xlCellTypeFormulas)
For Each r In rng
mesage = DQ & r.Formula & DQ
r.NumberFormat = mesage & ";" & mesage & ";" & mesage & ";"
Next r
End Sub
答案 0 :(得分:0)
Microsoft支持部门: [https://support.microsoft.com/en-us/kb/213612][1]
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
' The variable KeyCells contains the cells that will
' cause an alert when they are changed.
Set KeyCells = Range("A1:C10")
If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then
' Display a message when one of the designated cells has been
' changed.
' Place your code here.
MsgBox "Cell " & Target.Address & " has changed."
End If
End Sub
您可能还需要将VB代码放在工作表的代码部分中(而不是一般)。或者,缩小参数目标以仅包括所需的工作表。