简体   繁体   English

VBA复制并粘贴一个单元格与另一个单元格

[英]vba copy and paste one cell vs another

I am an extreme novice to VBA and have only found myself getting into it because as I research it seems to be the only way to accomplish what I want within excel. 我是VBA的极端新手,只是发现自己参与其中,因为在我研究时,这似乎是在excel中完成我想要的唯一方法。

In this case I have a button that should either copy data from specified cells in G or K to a different location of specified cells within the same worksheet. 在这种情况下,我有一个按钮,应该将数据从G或K中的指定单元格复制到同一工作表中指定单元格的不同位置。

The first part that copies data from either G16:G18 or K16:K18 works seamlessly. 从G16:G18或K16:K18复制数据的第一部分可以无缝工作。 I wonder if it is because there are no formulas in these cells, just numbers. 我想知道是否是因为这些单元格中没有公式,只有数字。

The next part of the code however seems to only copy from K21 or K19 and I am unsure why this keeps happening. 但是,代码的下一部分似乎仅从K21或K19复制,并且我不确定为什么这种情况一直发生。 I have formulas in these cells and I believe because of the order I have it is just copying the results from the last active range even if that result is “”. 我在这些单元格中有公式,并且我相信由于顺序原因,它只是从最后一个有效范围复制结果,即使结果为“”。

Below is the code I have now: 以下是我现在拥有的代码:

Private Sub CommandButton2_Click()
        ActiveSheet.Range("G16:G18").Copy
        ActiveSheet.Range("P38:P40").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=True, Transpose:=False

        ActiveSheet.Range("K16:K18").Copy
        ActiveSheet.Range("P38:P40").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=True, Transpose:=False

        ActiveSheet.Range("G21").Copy
        ActiveSheet.Range("K39").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=True, Transpose:=False

        ActiveSheet.Range("G17").Copy
        ActiveSheet.Range("K40").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=True, Transpose:=False

        ActiveSheet.Range("K21").Copy
        ActiveSheet.Range("K39").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=True, Transpose:=False

        ActiveSheet.Range("K19").Copy
        ActiveSheet.Range("K40").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=True, Transpose:=False

End Sub

Is it because of the pastevalues? 是因为粘贴值? Is there a way around this? 有没有解决的办法?

Any insight is greatly appreciated! 非常感谢任何见识!

查看粘贴到的位置,粘贴到K39,然后粘贴到K40,然后再次粘贴到K39,然后K40再次覆盖以前的粘贴,因此它总是看起来好像没有在做第一个副本,因为第二个已超过顶部。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 VBA用于将文本从单个未移动的单元格复制到粘贴到另一个单元格,每个粘贴/循环向下移动一个单元格 - VBA function to copy text from a single un-moving cell to paste to another cell, moving down one cell each paste/loop 在每个工作表匹配的单元格上复制一个单元格并将其粘贴到另一个VBA - Copy a cell on one sheet and paste it on another VBA based on cell from each sheet matching VBA:检查一个单元格是否包含某个值以及如何将该值复制/粘贴到另一个单元格 - VBA: Check if one cell contains some value and how to copy/paste that value to another cell VBA从一个工作簿复制并粘贴到另一个工作簿 - VBA to copy from one workbook and paste to another VBA-复制单元格并粘贴到另一张纸上的空白单元格中 - VBA - Copy cell and paste into an empty cell on another sheet 如何在列中复制一个单元格数据,然后将其粘贴,直到另一个值通过 VBA 进入列中? - How can i copy one cell data in a column and then paste it untill another value comes in the column through VBA? VBA 将单个单元格复制并粘贴到另一个工作表中定义的次数 - VBA Copy and paste a single cell a defined number of times in another worksheet VBA - 将字符串中的字符拆分,复制并粘贴到另一个单元格中(具有条件) - VBA - Split, copy and paste characters from string into another cell (with conditions) Excel VBA - 将每个单元分别复制并粘贴到另一个程序 - Excel VBA - Copy and Paste each cell Individually to another program 使用VBA并使用“偏移”将一系列单元格值复制并粘贴到另一张工作表中 - Copy and paste a range of cell values into another sheet with VBA and using Offset
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM