2014-01-18 3 views
0

У меня есть этот код, но он копирует формулы, и у меня просто есть значения. Я не слишком разбираюсь в 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

Изменить это:

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 
0

Если вы хотите, чтобы вставить значения, попробуйте следующее:

rng.Entirerow.Copy: sh5.Cells(Rows.Count, 1).End(xlUp).Offset(1,0).PasteSpecial xlPasteValues 

я думаю, вот что только отсутствующие в вашем коде.

Смежные вопросы