繁体   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