粘贴单元格值而不是公式

时间:2015-05-29 11:16:31

标签: excel excel-vba excel-2010 vba

我正在为多个工作表搜索一个字符串,一旦找到该字符串,就会将其复制到MergedData工作表。

我遇到的问题是应对公式而不是价值。我一直在寻找几个小时,似乎无法找到解决方案。

这是我目前正在使用的代码。

非常感谢您提供的任何帮助!

谢谢Aarron

Private Sub CommandButton1_Click()
Dim FirstAddress As String, WhatFor As String
Dim Cell As Range, Sheet As Worksheet
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
        .CutCopyMode = False
    End With

WhatFor = Sheets("SUB CON PAYMENT FORM").Range("L9") 


Worksheets("MergedData").Cells.Clear


If WhatFor = Empty Then Exit Sub


For Each Sheet In Sheets
    If Sheet.Name <> "SUB CON PAYMENT FORM" And Sheet.Name <> "MergedData" _ 
    And Sheet.Name <> "Details" Then


With Sheet.Columns(1)
   Set Cell = .Find(WhatFor, LookIn:=xlValues, LookAt:=xlWhole, _
   SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)


If Not Cell Is Nothing Then
   FirstAddress = Cell.Address
     Do
     Cell.EntireRow.Copy ActiveWorkbook.Sheets("MergedData").Range("A" & Rows.Count)_
     .End(xlUp).Offset(1, 0)
     Set Cell = .FindNext(Cell)
    Loop Until Cell Is Nothing Or Cell.Address = FirstAddress
End If
End With
End If

Next Sheet

Set Cell = Nothing  
End Sub

2 个答案:

答案 0 :(得分:1)

请勿将range.copy方法与目的地一起使用,但仅使用副本并使用PasteSpecialXlPasteType = xlPasteValues

Range.PasteSpecial Method (Excel)

答案 1 :(得分:1)

在其他人的帮助下,我所要做的就是更换。

Cell.EntireRow.Copy
ActiveWorkbook.Sheets("MergedData").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlValues

有了这个:

times = np.arange(0, duration, 1 / sfreq)
nse1 = np.random.rand(times.size) * nse_amp
x =  amp * np.sin( 2 * np.pi * 200 * times            ) + nse1
x2 = np.array_split(x,epochs)