【发布时间】:2018-05-12 08:45:14
【问题描述】:
继我之前的问题之后,我现在想在单元格范围内复制粘贴值。
我之前的查询中使用的代码是;
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
【问题讨论】:
-
第一个代码有什么问题?为什么不把问题说清楚,只显示第二个代码示例并清楚说明错误是什么?
-
@pnuts 存在运行时错误 '5' 无效的过程调用或参数
-
我建议你谷歌或在 VBA 帮助中查找单元格和范围语法。
标签: vba excel range copy-paste