簡體   English   中英

粘貼行值而不是公式

[英]Paste Row Values not Formulas

嗨,我已經在Google周圍搜索了一段時間,但目前無法找到針對我特定問題的解決方案。 所以問題很簡單,我想選擇並復制a並僅粘貼值,而不粘貼生成值的公式。

我檢查了: 復制整個行(值不是公式)VBA

https://msdn.microsoft.com/zh-CN/library/aa195818(v=office.11​​).aspx

我正在使用的當前代碼如下所示,我目前僅使用“ OutputWorksheet.Paste”(粘貼行),但它也包含公式並嘗試了“ OutputWorksheet.PasteSpecial.xlPasteValues”,但它始終拋出“編譯錯誤:預期函數”或變量”

我們將不勝感激任何幫助,或者是一種更好的方法,它基於一張紙中的cboMADropDown值查找行並將其復制並粘貼到另一只紙中而沒有公式的表中。

With InputWorksheet                                                     ' Set sheet we want to search
Set FindRow = .Range("O:O").Find(What:=cboMADropDown, LookIn:=xlValues) ' Set FindRow container by searching Column F with cboMADropDown Value and look for the cell value to compare
End With                                                                ' End the With Statement
FindRowNumber = FindRow.Row                                             ' Set the FindRow row value to a number


InputWorksheet.Rows(FindRowNumber).EntireRow.Copy                       'Grab contents of entire row which is going to be updated
LastRow = OutputWorksheet.Range("A" & Rows.Count).End(xlUp).Row         'Finds the last blank Row on the MA tracking history sheet

OutputWorksheet.Activate                                                'Activate the worksheet so the .select command works with no errors
OutputWorksheet.Rows(LastRow).Select                                    'Select last blank row from MA tracking history
OutputWorksheet.Paste                        'Paste contents of the clipboard to backup
OutputWorksheet.Range("O" & LastRow).Value = TimeStamp                  'Add time stamp for the update

只要這是我的2美分...您的最后一排給您最后占用的行,而不是第一行可用...如果我沒看錯的話? 所以您可能需要這樣的東西才能真正獲得第一行空白:

LastRow = OutputWorksheet.Range("A" & Rows.Count).End(xlUp).Row + 1

然后,您不需要復制/粘貼值,只需執行rangeB.Value = rangeA.Value這樣就只會復制值,而不是公式。 您的情況如下所示:

With InputWorksheet                                                     ' Set sheet we want to search
    Set FindRow = .Range("O:O").Find(What:=cboMADropDown, LookIn:=xlValues) ' Set FindRow container by searching Column F with cboMADropDown Value and look for the cell value to compare
End With                                                                ' End the With Statement
FindRowNumber = FindRow.Row                                             ' Set the FindRow row value to a number

With OutputWorksheet
    LastRow = .Range("A" & Rows.Count).End(xlUp).Row                 'Finds the last blank Row on the MA tracking history sheet
    .Rows(LastRow).Value = InputWorksheet.Rows(FindRowNumber).Value
    .Range("O" & LastRow).Value = TimeStamp                  'Add time stamp for the update
End With

值得一提的是,鑒於您實際上並不需要整行(我在這里可能是錯誤的),則可以更好地指定范圍(除非您在“ O”列之外有更多值):

FindRowNumber = InputWorksheet.Range("O:O").Find(What:=cboMADropDown, LookIn:=xlValues).Row 'assign the row number directly to the variable (as with the LastRow, unless you need differently for other reasons)
With OutputWorksheet
    LastRow = .Range("A" & Rows.Count).End(xlUp).Row
    .Range("A" & LastRow & ":N" & LastRow).Value = InputWorksheet.Range("A" & FindRowNumber & ":N" & FindRowNumber).Value
    .Range("O" & LastRow).Value = TimeStamp
End With

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM