gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 21:10:08 24 4
gpt4 key购买 nike

我正在尝试创建一个单元格来在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com