[英]Excel macro to find a cell in a sheet and copy the entire row in another sheet
[英]specifying a cell in a sheet in an Excel macro
我正在编写一个Excel宏,并具有类似于以下内容的部分,在该部分中,我浏览了名为“ daf”的工作表中的一列,并将其与另一工作表中的单元格进行比较:
For i = 2 To 75
If Range("the daf!C" + Trim(Str(i))) = Range("scratchpad!Q30") Then
notes = notes + Range("scratchpad!P30")
Exit For
End If
Next
问题在于它会产生“ #Value!”的结果。 问题似乎是在工作表名称中有一个空格,因为当我将“ daf”替换为“ scratchpad”时,它不会产生错误。 如果我说的是正确的,那么当工作表名称包含空格时,如何引用工作表中的单元格?
采用
Sheets("the daf").Range("C" & i)
代替
Range("the daf!C" + Trim(Str(i)))
例:
If Sheets("the daf").Range("C" & i).Value = Sheets("scratchpad").Range("Q30").Value Then
编辑
如果您仍然想使用所使用的方法,请尝试以下方法
Range("'the" & " " & "daf'!C" & i)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.