【发布时间】:2016-10-17 00:06:25
【问题描述】:
如果您能提供帮助,我将不胜感激,因为我真的很想让它发挥作用。我这里有一些代码,旨在从电子表格的一部分中提取信息并将其粘贴到电子表格另一部分的表格中。
For i = 1 To 24
Range("J11:J100").Select
Set foundCell = Cells.Find(What:="PL " & i, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
If Not foundCell Is Nothing Then
foundCell.Activate
foundCell.Copy
Range("P" & (i + 10)).Select
ActiveSheet.Paste
End If
Next
主要问题是我还想使用 foundCell 作为参考从周围的列中复制信息,例如。 foundCell.Offset(, -4).Copy
我添加了这个,但它不起作用(附录已标记):
For i = 1 To 24
Range("J11:J100").Select
Set foundCell = Cells.Find(What:="PL " & i, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
If Not foundCell Is Nothing Then
foundCell.Activate
foundCell.Copy
Range("P" & (i + 10)).Select
ActiveSheet.Paste
' BEGIN ADDITION
foundCell.Offset(, -4).Copy
Range("S" & (i + 10)).Select
ActiveSheet.Paste
'END ADDITION
End If
Next
我进行了测试,发现 foundCell 现在引用的是数据粘贴到的范围,而不是找到它的原始范围。
谁能帮帮我?我对任何事情都持开放态度。我觉得最好的解决方案是将 foundCell 变成一个范围,但我不知道该怎么做。
【问题讨论】: