我一直在阅读和尝试代码,但它仍然无效。有人能告诉我我做错了什么吗?我的excel文件在一个选项卡上有公式,我试图复制并粘贴到另一个选项卡,但我尝试的一切都是粘贴公式而不是我需要的文本输出。
Dim rowCount2 As Long, shtSrc As Worksheet
Dim shtDest As Worksheet
Dim rng2 As Range
Dim currentRow As Long
Set shtSrc = Sheets("Data")
Set shtDest = Sheets("Audit")
rowCount2 = shtSrc.Cells(Rows.Count, "A").End(xlUp).Row
Set rng2 = shtSrc.Range("A1:A" & rowCount2)
currentRow = 1
For Each cell2 In rng2.Cells
If cell2.Value <> "" Then
cell2.Copy shtDest.Range("B" & currentRow).PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
cell2.Offset(0, 1).Copy ("C" & currentRow)
cell2.Offset(0, 2).Copy ("G" & currentRow)
currentRow = currentRow + 1
End If
Next cell2
答案 0 :(得分:3)
您不能将PasteSpecial
与Copy
方法的目标参数一起使用 - 您必须使用单独的操作,但由于您只复制单个单元格,因此您只需指定值:
shtDest.Range("B" & currentRow).Value2 = cell2.Value2
shtDest.Range("C" & currentRow).Value2 = cell2.Offset(0, 1).Value2
shtDest.Range("G" & currentRow).Value2 = cell2.Offset(0, 2).Value2