我有这个代码,但它复制公式,我只有值。 我对VBA并不太了解。
Dim sh4 As Worksheet, sh5 As Worksheet, lr As Long, rng As Range
Set sh4 = Sheets("Transfer_New")
Set sh5 = Sheets("Closed_Loans")
lr = sh4.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh4.Range("A2:A" & lr)
Application.Cursor = xlHand
iReply = MsgBox(Prompt:="Are you sure you want to transfer client to CLOSED_LOANS?", _
Buttons:=vbYesNo, Title:="Document Production")
If iReply = vbYes Then
Application.Cursor = xlWait: rng.EntireRow.Copy sh5.Cells(Rows.Count, 1).End(xlUp)(2): Application.Cursor = xlNorthwestArrow
End If
End Sub
答案 0 :(得分:0)
改变这个:
If iReply = vbYes Then
Application.Cursor = xlWait: rng.EntireRow.Copy sh5.Cells(Rows.Count, 1).End(xlUp)(2): Application.Cursor = xlNorthwestArrow
End If
对此(没有非常好的理由 - 当然不是为了易读性/清晰度 - 在一行上放置多行代码(这就是:
分隔符所做的那样)。
If iReply = vbYes Then
Application.Cursor = xlWait
rng.EntireRow.Copy sh5.Cells(Rows.Count, 1).End(xlUp)(2)
Application.Cursor = xlNorthwestArrow
End If
然后将其更改为:
Dim destRng as Range
Set destRng = sh5.Cells(Rows.Count, 1).End(xlUp).Offset(1,0)
If iReply = vbYes Then
Application.Cursor = xlWait
destRng.Value = rng.Value
Application.Cursor = xlNorthwestArrow
End If
答案 1 :(得分:0)
如果要粘贴值,请尝试以下操作:
rng.Entirerow.Copy: sh5.Cells(Rows.Count, 1).End(xlUp).Offset(1,0).PasteSpecial xlPasteValues
我认为这是代码中唯一遗漏的内容。