vba - Excel VBA 阻止我粘贴值

标签 vba excel

I made a macro that computes the STDEV of a selection and puts it in the status bar, and so is called whenever the selection is changed.但是,当我复制一个范围时,它具有阻止我在任何地方粘贴值的意外效果。我可以复制,但是当我单击其他位置粘贴时,粘贴按钮变为灰色,并且我失去了选择。
如何取回我的糊状物?最好通过更改宏而不是添加新宏。

这是代码:

Public st As Double
Public rng as Range

Sub stdev()
On Error Resume Next
st = Application.WorksheetFunction.stdev(rng)
If Err.Number <> 0 then
    st = 0
End If
Application.DisplayStatusBar = True
Application.StatusBar = "Stdev: " & st
End Sub

然后:
Private Sub Worksheet_SelectionChange(ByVal Target as Range)
Set rng = Target
Call stdev
End Sub

最佳答案

如果你改变了怎么办

Private Sub Worksheet_SelectionChange(ByVal Target as Range)
Set rng = Target
Call stdev
End Sub


Private Sub Worksheet_SelectionChagne(ByVal Target as Range)
If Application.CutCopyMode = 1 Then Exit Sub
Set rng = Target
Call stdev
End Sub

当您复制和粘贴某些内容时,这应该绕过您的子例程,而无需添加更多代码。

关于vba - Excel VBA 阻止我粘贴值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37794923/

相关文章:

python - 如何让unoconv在转换为pdf之前自动计算公式?

excel - VBA Excel 比较两个列表是否匹配,在单独的工作表上输出结果

excel - 在delphi上将excel文件导入到datagrid

vba - 每个页面的 MS word 宏 vba

ms-access - 无法将字典作为参数传递给 VBA 函数

excel - 在 Excel/VBA 中将日期和时间连接到单个单元格中

excel - 循环遍历单元格并更改字体

excel - 如何将 HEX 转换为 BIN,在 EXCEL 2010 中一次一个字符

VBA Zip 文件错误

vba - 获取VBA对话框的选项(xlDialogSort)