vba - Copy and paste data and have it be updated automatically
问题描述
So I created a copy and paste function. I had help previously with an error I encountered. However, I am now wanting to make the values copy and pasted to be updated when the original date is changed. So, my original thought was to paste something like =(ws.Cells(i, j)
. And have a nested for loop to with the values i
staying the same as below and j
going in between 6 and 16. But I couldn't get that to work.
If there is a special paste function or something that I am unaware of that would be great. Is there a way to get copy and paste data but also have it still be reliant on the original (updates when the original is changed).
If there is another question with a solution to this problem then I didn't see it and I am sorry.
I have my code below. And any help would be appreciated.
Private Sub CommandButton1_Click()
Dim rng As Range
Dim ws As Worksheet
Set ws = Worksheets("Goals")
a = Worksheets("Goals").Cells(Rows.Count, 7).End(xlUp).Row
For i = 2 To a
If Worksheets("Goals").Cells(i, 20).Value = "Red" Then
ws.Activate
Set rng = ws.Range(ws.Cells(i, 6), ws.Cells(i, 16)) 'columns to be copied
rng.Copy
Worksheets("Scorecard").Activate
b = Worksheets("Scorecard").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Scorecard").Cells(b + 1, 2).Select
ActiveSheet.Paste
Worksheets("Goals").Activate
End If
Next
Application.CutCopyMode = False
Worksheets("Forms").Activate
Worksheets("Forms").Cells(22, 10).Select 'going back to the Forms page
End Sub
解决方案
尝试这个
Worksheets("Goals").Range("I6:I16").Copy
Worksheets("Scorecard").Paste Link:=True
如果在此过程中切换床单,我希望您不会介意..
谢谢
推荐阅读
- r - 基础 R 中绘图的小问题 - 绘图顶部显示不需要的线条
- python - python - 如何将不同级别的日志写入python日志模块中的单独文件?
- ssh - Windows 10 和 ssh 上的 Visual Studio Code Live 服务器
- vert.x - 如何在 Vertx 中设置活动配置文件,类似于 Spring Boot
- jquery - 将 css 框扩展到正确的文本高度
- r - 对 R 中的列求和时的问题
- r - 根据重复的字符串值将行拆分为具有列名的多列
- html - 强制以 css 网格开始新行
- apache-spark - Spark - 计算数组列的统计信息 (ArrayType)
- android - 错误:程序类型已存在:com.google.gson.JsonNull 如何找到重复的库