首页 > 解决方案 > 想要在 n 次复制功能中复制单元格值而不是公式

问题描述

Sub CopyHeaders()
Dim copyTimes As Long
Dim i As Long
Dim n As Integer

   copyTimes = Range("B3")
If copyTimes > 0 Then
    For i = 1 To copyTimes
    Range("C3").Copy Cells((i * 1) + 1, "F")
    Next i
End If   
End Sub

标签: excelvba

解决方案


这似乎对我有用。

Option Explicit

Sub CopyHeaders()
    Dim copyTimes As Long
    copyTimes = Range("B3")

    If copyTimes > 0 Then
        Range("F2").Resize(copyTimes).Value = Range("C3").Value
    End If
End Sub

如果您想更好地控制粘贴类型(例如,仅值、仅值和数字格式等),您也可以使用Range.Copyand 。Range.PasteSpecial


推荐阅读