【发布时间】:2014-05-10 13:29:38
【问题描述】:
我想修改此宏以粘贴复制的行及其原始格式,并且只有它们的值,因为被复制的行中包含公式。我尝试将 PasteSpecial xlPasteValues 放在 Rows(j+6) 之后,但这并没有成功。
Sub customcopy()
Dim strsearch As String, lastline As Integer, tocopy As Integer
strsearch = CStr(InputBox("enter the string to search for"))
lastline = Range("A65536").End(xlUp).Row
j = 1
For i = 1 To lastline
For Each c In Range("C" & i & ":Z" & i)
If InStr(c.Text, strsearch) Then
tocopy = 1
End If
Next c
If tocopy = 1 Then
Rows(i).Copy Destination:=Sheets("Sheet2").Rows(j + 6)
j = j + 1
End If
tocopy = 0
Next i
End Sub
【问题讨论】:
-
您可能想在 tocopy=1 之后添加类似 exit for 的行。因为如果复制条件已经满足,为什么还要循环呢?此外,您没有声明 J. tocopy,lastline,J 因为 Long 不会造成伤害。