excel - 复制并粘贴到excel上而不删除单元格当前内容

标签 excel cell copy-paste vba

我正在尝试创建一个单元格来在 excel 中构建 jar 头回复电子邮件。我需要能够将文本粘贴到一个单元格中而不删除该单元格中已经存在的信息(并且我需要能够重复执行此操作。)我基本上是在寻求帮助创建一个具有类似“副本”的单元格并将'属性粘贴为word doc。即,当我将文本粘贴到单元格中时,它将在先前文本下方插入新文本,而不是用剪贴板替换现有文本。

我绝对可以在 VBA 中使用一些帮助进行编码。如果有什么需要澄清的,请告诉我!谢谢

最佳答案

我编写了代码来执行您的要求,但我不确定它是否真的是您需要的。

Alt+F11
双击您想要处理的工作表(左侧)

Paste Code

粘贴此代码。

请注意,此代码将允许您通过点击删除来清除单元格。

否则很难删除。

请注意,这实际上会附加您尝试使用编辑进行编辑的任何单元格。

Dim currentVal
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If currentVal <> vbNullString And Target.Value <> vbNullString Then
    Application.EnableEvents = False
    Target.Value = currentVal & vbCrLf & Target.Value
    currentVal = Target.Value
    Application.EnableEvents = True
Else
    currentVal = Target.Value
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.CountLarge = 1 Then currentVal = Target.Value
End Sub

这个怎么运作:

Working

希望最终编辑可以与在移动设备上键入的合并单元格一起使用无法测试:
Dim currentVal
Private Sub Worksheet_Change(ByVal Target As Range)
If currentVal <> vbNullString And Target.Cells(1,1).Value <> vbNullString Then
    Application.EnableEvents = False
    'Use this to add an extra line instead
    Target.Cells(1,1).Value = currentVal & vbLf & vbLf & Target.Cells(1,1).Value
    'Target.Cells(1,1).Value = currentVal & vbLf & Target.Cells(1,1).Value
    currentVal = Target.Cells(1,1).Value
    Application.EnableEvents = True
Else
    currentVal = Target.Cells(1,1).Value
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
currentVal = Target.Cells(1,1).Value
End Sub

关于excel - 复制并粘贴到excel上而不删除单元格当前内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38904004/

相关文章:

excel - 查找日期,返回前 5 天的总和

excel - 如何禁用 Excel 在复制/粘贴后自动更改单元格引用?

excel - 创建具有不同访问权限的 Excel,例如在运行时读/写

visual-studio-2010 - Visual Studio 2010 : While debugging, 如何从变量中复制包含回车符的字符串值?

javascript - 如何 "copy/paste"子图——JointJS

excel - 如何在VBA中提取第二个空格后的文本

excel - 通过vba计算包裹单元格中的行数

c - 在C中访问Excel工作表单元格属性

Excel 简单 : in what way is my simple formula wrong?

html - 用户选择静止图像复制到剪贴板