在单元格范围内复制粘贴值

Copy paste values within cell range

根据我之前的问题,我现在想复制单元格范围内的粘贴值。

我之前查询中使用的代码是;

Sub CopyYesInW()
Dim lastRow As Long, i As Long
'determine last row in column W
lastRow = Cells(Rows.Count, "W").End(xlUp).Row
For i = 1 To lastRow
    'if Yes in W then copy from P to W in current row
    If Cells(i, "W").Value = "Yes" Then
        Cells(i, "P").Value = Cells(i, "P").Value
    End If
    If Cells(i, "W").Value = "Yes" Then
        Cells(i, "U").Value = Cells(i, "U").Value
    End If
Next
End Sub

我修改了下面脚本中的代码,以检查单元格范围 C6:N6 中的值 = Yes,然后将值复制粘贴到 C9:N9 中的单元格上。但是我不确定我做错了什么。存在运行时错误“5”无效过程调用或参数

Sub CopyYesInForecast()
Dim lastRow As Long, i As Long
'determine last row in column W
lastRow = Cells("C6")
For i = 1 To lastRow
'if Yes in W then copy from P to W in current row
    If Cells(i, "C6:N6").Value = "Yes" Then
        Cells(i, "C9:N9").Value = Cells(i, "C9:N9").Value
    End If
Next
End Sub

虽然您的叙述很单薄,但也许这接近您的尝试。

Sub CopyYesInForecast()
    Dim c As Long

    For c = range("C:C").column to range("N:N").column
        If Cells(6, c).Value = "Yes" Then
            Cells(9, c) = Cells(6, c).Value
        End If
    Next
End Sub

这会查看第 6 行的 C 列到 N 列,如果找到 Yes,则将值转移到第 9 行中的同一列。