粘贴单元格值而不是公式
Paste cell values rather than formulas
我在多个 sheet 中搜索一个字符串,一旦找到该字符串,它就会将其复制到 MergedData sheet。
我遇到的问题是处理公式而不是值。我已经搜索了几个小时,但似乎找不到解决方案。
这是我目前使用的代码。
非常感谢您提供的任何帮助!
谢谢亚伦
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
不要对目标使用 range.copy
方法,而仅使用复制并使用 PasteSpecial
和 XlPasteType = xlPasteValues
在其他人的帮助下,我所要做的就是更换。
Cell.EntireRow.Copy ActiveWorkbook.Sheets("MergedData").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
有了这个:
Cell.EntireRow.Copy
ActiveWorkbook.Sheets("MergedData").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlValues
我在多个 sheet 中搜索一个字符串,一旦找到该字符串,它就会将其复制到 MergedData sheet。
我遇到的问题是处理公式而不是值。我已经搜索了几个小时,但似乎找不到解决方案。
这是我目前使用的代码。
非常感谢您提供的任何帮助!
谢谢亚伦
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
不要对目标使用 range.copy
方法,而仅使用复制并使用 PasteSpecial
和 XlPasteType = xlPasteValues
在其他人的帮助下,我所要做的就是更换。
Cell.EntireRow.Copy ActiveWorkbook.Sheets("MergedData").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
有了这个:
Cell.EntireRow.Copy
ActiveWorkbook.Sheets("MergedData").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlValues