简体   繁体   English

遍历行复制并粘贴到VBA Excel中的另一个工作表

[英]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.

相关问题 Excel VBA:遍历单元格并将值复制到另一个工作表 - Excel VBA: Loop through cells and copy values to another worksheet Excel-VBA将数据从一个工作表复制到另一工作表并粘贴到新行 - Excel-VBA Copy data from one worksheet to another worksheet and paste in new row 如何选择组合框值的行,然后使用带有VBA Excel的命令按钮将其复制并粘贴到另一个工作表范围 - how to select the row of combobox value then copy and paste to another worksheet range using command button with VBA Excel 如何捕获通过Excel VBA中的复制/粘贴添加的工作表 - How to capture worksheet being added through Copy/Paste in Excel VBA Excel/VBA - 根据日期将数据复制并粘贴到特定行中的工作表中 - Excel/VBA - Copy and paste data into a worksheet in a specific row based on date Excel宏:将工作表复制并粘贴到另一个工作表中 - Excel Macro: Copy and paste worksheet into another worksheet 在一个工作表中复制一行并粘贴到另一个工作表中 - copy a row in one worksheet and paste in another worksheet VBA代码可从一个工作表复制数据并将其粘贴到另一工作表的最后一行下方 - VBA code to copy data from one worksheet & paste below last row of another worksheet Excel:如何将包含某些文本的行复制到另一个工作表(VBA) - Excel: How to copy a row if it contains certain text to another worksheet (VBA) Excel VBA-通过循环将数据从一个工作表复制到另一个工作表 - Excel VBA - Copy data from one worksheet to another via loop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM