我想将特定工作表中的三个单元格(“N2”,“N3”和“N4”)复制到同一工作表中的三个其他单元格(“P2”,“P3”和“P4”)。目前唯一正确复制的值是单元格“N3”。单元格“P4”为空,单元格“P2”仅包含“0:00”(使用[t]:mm格式)。如何正确复制所有单元格?你可以看到下面的代码。还试过使用“.copy”和“.PasteSpecial xlPasteValues”,但这也不起作用。
Private Sub adjustSheets()
Dim ws As Worksheet
Dim cnt&, lRow&, sRow&
Dim formula$
Application.DisplayAlerts = False
For Each ws In ThisWorkbook.Sheets
If ws.Range("Z1") <> "Specific_Sheet" Then GoTo ContLoop
ws.Range("Block").EntireRow.Delete
With ws
lRow = .Cells(Rows.Count, "B").End(xlUp).row
cnt = 1
formula = vbNullString
For sRow = 12 To lRow Step 7
If cnt = 1 Then
formula = "="
Else
formula = formula & "+"
End If
formula = formula & Replace("SUM(C#:I#)", "#", sRow)
cnt = cnt + 1
Next
' apply formula
.Range("N4").formula = formula
.Range("P2").Value = .Range("N2").Value
.Range("P3").Value = .Range("N3").Value
.Range("P4").Value = .Range("N4").Value
End With
ContLoop:
If ws.Visible = xlSheetVisible Then Application.Goto ws.Range("A1"), True
Next
End Sub
感谢任何帮助。