简体   繁体   English

如何使用VBA将范围内的值从一张纸复制到另一张纸上的预定义订单?

[英]How to copy the values in a range from one sheet to and paste it another sheet on a predefied order using VBA?

I am trying to copy the values in a specific range from one sheet to another.我试图将特定范围内的值从一张纸复制到另一张纸。 While pasting the values to the new sheet, there should be a predefined order in which the values are pasted.将值粘贴到新工作表时,应该有预定义的值粘贴顺序。


I have created the program, but there comes an error in definition of For loop.我已经创建了程序,但是在 For 循环的定义中出现错误。 Please note that in this example Num_Tacksta = 2, m = 9 (These two are variables).请注意,在此示例中 Num_Tacksta = 2, m = 9(这两个是变量)。

Sub New_Try(m)

Dim n, i, j, x, k, a, rowinres, Num_Tacksta, Num_TackMul As Variant
Num_Tacksta = Sheets("ALLO").Range("E4").Value
Num_TackMul = (Sheets("ALLO").Range("E4").Value) * 2
x = Sheets("ALLO").Range("E4").Value


For rowinres = 2 To Num_Tacksta Step 1
    For i = 2 To Num_TackMul Step 2
        Sheets("Final").Range("A" & rowinres &, ",M" & rowinres).Copy Destination:=Sheets("Results").Range("A" & i)
        rowinres = rowinres + 1
    Next i

    For j = 3 To Num_TackMul Step 2
        Sheets("Dummy_Result").Range("A" & rowinres &, ",M" & rowinres).Copy Destination:=Sheets("Results").Range("A" & j)
        rowinres = rowinres + 1
    Next j

    For k = Num_TackMul + 1 To m Step 1
        Sheets("Dummy_Result").Range("A" & rowinres &, ",M" & rowinres).Copy Destination:=Sheets("Results").Range("A" & k)
        rowinres = rowinres + 1
    Next k

Next rowinres


End Sub

To my basic Knowledge in VBA, I think the problem is in this Sheets("Dummy_Result").Range("A:M" & rowinres).Copy Destination:=Sheets("Results").Range("A" & j) line.根据我在 VBA 中的基本知识,我认为问题出在这个Sheets("Dummy_Result").Range("A:M" & rowinres).Copy Destination:=Sheets("Results").Range("A" & j)线。 I would like to also ask if there is any simple method available.我也想问有没有什么简单的方法可以用。

I am new to programming and also to Stack Overflow.我是编程新手,也是 Stack Overflow 的新手。 Helping me in this would be really helpful!在这方面帮助我真的很有帮助! I thank you guys in advance.我提前感谢你们。

Try colon instead of comma in your copy range:在复制范围内尝试冒号而不是逗号

Sheets("Results").Range("A" & rowinres & ":M" & rowinres).Copy Destination:=Sheets("Final").Range("A" & i)

A comma is used in functions such as SUM() but a colon is used to specify a range.逗号用于SUM()等函数,但冒号用于指定范围。

暂无
暂无

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

相关问题 VBA复制范围值并粘贴到另一张工作表中 - VBA Copy range values and paste in another sheet 使用VBA并使用“偏移”将一系列单元格值复制并粘贴到另一张工作表中 - Copy and paste a range of cell values into another sheet with VBA and using Offset 将范围从一张纸复制/粘贴到另一张纸 - Copy/Paste Range from one sheet to another 如何使用vba将多列数据从一张工作表复制并粘贴到另一张工作表 - How to copy and paste multiple column data from one sheet to another sheet using vba Excel VBA 从一个工作表中复制范围并将其一次一个单元格地粘贴到另一张工作表中 - Excel VBA copy range from one sheet and paste it one cell at a time in another sheet 使用excel VBA将数据从一张纸复制并粘贴到另一张纸,然后从第二张纸复制到第三张纸 - Copy and paste data from one a sheet to another sheet, and from second sheet to third using excel VBA Excel 2007 VBA:如何从一张纸上的动态范围复制和粘贴到另一张纸的第一行? - Excel 2007 VBA: How do I copy and paste from a dynamic range on one sheet to the first empty row of another sheet? 要将值从工作表1复制到工作表2并使用vba将其粘贴到所需的位置 - To copy values from sheet 1 to sheet 2 and paste it at desired location using vba 使用vba以相反的顺序将数据从一张纸复制到另一张纸 - Copy data from one sheet to another in reverse order using vba 使用VBA excel从一张工作表中复制表格并将其粘贴到另一张工作表的下一个空行中 - copy a table from one Sheet and paste it in the next empty row of another Sheet using VBA excel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM