简体   繁体   English

如何将同一列中的值复制到下一列? Excel VBA

[英]How to copy the values from the same column into the next columns? Excel VBA

I am trying to copy the values from the same range (G8:G1000), and then paste those values to the next column (H8:H1000).我正在尝试从同一范围 (G8:G1000) 复制值,然后将这些值粘贴到下一列 (H8:H1000)。 However, I then want to copy that same range (G8:G1000) again, but then paste the values into I8:I1000, and do that at least 100 times.但是,然后我想再次复制相同的范围 (G8:G1000),然后将值粘贴到 I8:I1000 中,并至少执行 100 次。 Essentially, there is a formula in column G that is producing randomized values, and I want to copy those unique values into all of the columns following column G. I believe I will need some sort of For Next loop, where it keeps selecting the values from G column, and then pasting them to the next column after the previously pasted into column, but I have very little VBA knowledge to figure this out.本质上,G 列中有一个公式正在生成随机值,我想将这些唯一值复制到 G 列之后的所有列中。我相信我需要某种 For Next 循环,它会在其中不断选择值从 G 列,然后将它们粘贴到先前粘贴到列之后的下一列,但是我对 VBA 的了解很少。 Does anyone have a potential solution for this?有没有人对此有潜在的解决方案? Any help is appreciated.任何帮助表示赞赏。

Thanks.谢谢。

Generate Columns生成列

Option Explicit

Sub generateColumns()
    
    Const rgAddress As String = "G8:G1000"
    Const cCount As Long = 100
    
    Dim rg As Range: Set rg = Range(rgAddress)
    'rg.Formula = "=RANDBETWEEN(1,100)"
    
    Application.ScreenUpdating = False
    
    Dim c As Long
    For c = 1 To cCount
        rg.Offset(, c).Value = rg.Value
    Next c

    Application.ScreenUpdating = True

End Sub

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM