2016-07-25 33 views
0

我有一些代碼可以搜索我需要複製的文本,但是我意識到這些代碼正在執行公式。我需要它來簡單地粘貼單元格的值。我不確定如何編輯以下內容以實現此目的。有什麼想法嗎?編輯代碼只複製值而不是公式

With Initiatives.Range("B3:B500") 

    Rcount = 0 

    For I = LBound(MyArr) To UBound(MyArr) 


     Set Rng = .Find(What:=MyArr(I), _ 
         After:=.Cells(.Cells.Count), _ 
         LookIn:=xlFormulas, _ 
         LookAt:=xlPart, _ 
         SearchOrder:=xlByRows, _ 
         SearchDirection:=xlNext, _ 
         MatchCase:=False) 
     If Not Rng Is Nothing Then 
      FirstAddress = Rng.Address 
      Do 
       Rcount = Rcount + 1 

       Rng.EntireRow.Copy NewSh.Rows(Rcount) 



       Set Rng = .FindNext(Rng) 
      Loop While Not Rng Is Nothing And Rng.Address <> FirstAddress 
     End If 
    Next I 
End With 
+2

'NewSh.Rows(Rcount時).value的= Initiatives.Rows(Rng.Row).value' –

+0

@ScottCraner運作良好謝謝!如果你把它作爲答案發布,我會非常樂意接受它來結束這個問題。作爲一個方面說明,我將如何修改這個也複製格式但不是公式? – TonyP

回答

1

嘗試修改拷貝代碼:

Rng.EntireRow.Copy 
NewSh.Cells(RCount,1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ 
    :=False, Transpose:=False 

這給你複製整個行,艇員選拔你想要什麼方法粘貼的選項。

+0

這工作得很好。它確實減慢了整體速度。我想這是可以預料的。 – TonyP

+0

你可以嘗試在整個範圍內一次,讓它更快:) –

0

而是從源一個範圍應對所述到目的地範圍

Rng.EntireRow.Copy NewSh.Rows(Rcount)

具有目標範圍值的=源範圍值。就像使用數組填充範圍值一樣。

NewSh.Rows(Rcount).Value = Rng.EntireRow.Value