[英]loop through row copy and paste to another worksheet in VBA Excel
I am trying to copy and paste these rows - one at the time in VBA 我正在尝试复制和粘贴这些行-一次在VBA中
Name Col1 Col 2 Col 3
Tom LTD - 617 LTD - 2236 LTD - 964
David LTD - 289 LTD - 045 LTD - 055
Peter LTD - 112 LTD - 687 LTD - 899
I need to transpose and paste value for each row in the same column like this 我需要像这样在同一列中的每一行转置并粘贴值
Tom
LTD - 617
LTD - 2236
LTD - 964
Is there a do loop in VBA that can help me achieve this? VBA中有一个do循环可以帮助我实现这一目标吗?
I need the VBA version of how to do this as I'm automating this worksheet, my example is more complex but what I want to do can be illustrated with a simple example like the above. 在使此工作表自动化时,我需要如何执行此操作的VBA版本,我的示例更加复杂,但是可以通过上面的简单示例来说明我想做的事情。 Can anyone suggest a VBA solution - I need to understand how do you loop thorough rows one at the time and outputting them in different location and position.
谁能建议一个VBA解决方案-我需要了解您如何一次遍历完整的行并将其输出到不同的位置和位置。
If your source table is as symmetric as your question suggests and if this is a one-off transformation, I would use formulae to arrange the transposition. 如果您的源表像您的问题所建议的那样对称,并且这是一次转换,那么我将使用公式来安排换位。 If either of these are untrue, it will be -1 for an inadequate question.
如果其中任何一个都不成立,那么对于不足的问题,它将为-1。
I assume your source table starts in cell A1 and there is nothing to stop me using column F. 我假设您的源表从单元格A1开始,并且没有什么可以阻止我使用列F。
Paste the following into cells F2:F5 将以下内容粘贴到单元格F2:F5中
=INDIRECT(ADDRESS((ROW(F2)-2)/4+2,1,4))
=INDIRECT(ADDRESS((ROW(F3)-3)/4+2,2,4))
=INDIRECT(ADDRESS((ROW(F4)-4)/4+2,3,4))
=INDIRECT(ADDRESS((ROW(F5)-5)/4+2,4,4))
This will set cell F2:F5 to the values from row 2. Copy this block of 4 cells (repeat block of 4 cells not cell F5) down as far as necessary. 这会将单元格F2:F5设置为第2行中的值。根据需要向下复制此4个单元格的块(重复4个单元格的块而不是单元格F5)。 The values you seek will be in a column as formulae .
您寻求的值将在公式栏中。
Use Copy and Paste Special, Values, to get the values you seek as values . 使用“复制并粘贴特殊值”来获取您寻求的值作为值 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.