【问题标题】:How to copy the values from the same column into the next columns? Excel VBA如何将同一列中的值复制到下一列? Excel VBA
【发布时间】:2021-06-02 17:00:33
【问题描述】:

我正在尝试复制同一范围 (G8:G1000) 中的值,然后将这些值粘贴到下一列 (H8:H1000)。但是,然后我想再次复制相同的范围 (G8:G1000),然后将值粘贴到 I8:I1000 中,并至少执行 100 次。本质上,G 列中有一个公式正在生成随机值,我想将这些唯一值复制到 G 列之后的所有列中。我相信我需要某种 For Next 循环,它会在其中不断选择值从 G 列,然后将它们粘贴到先前粘贴到列中的下一列,但我对 VBA 的了解很少。有没有人对此有潜在的解决方案?任何帮助表示赞赏。

谢谢。

【问题讨论】:

    标签: excel vba loops copy paste


    【解决方案1】:

    生成列

    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
    

    【讨论】:

    • 漂亮,成功了!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多