0

嗨,我一直在谷歌搜索一段时间,目前无法找到解决我的具体问题的方法。所以问题很简单我想选择并复制 a 并只粘贴值而不是生成值的公式。

我检查过: 复制整行(值不是公式)VBA

https://msdn.microsoft.com/en-us/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
4

1 回答 1

0

只是我这里的 2 美分……你的 lastrow 给你最后占用的行,而不是可用的第一行……如果我没记错的话?所以你可能需要这样的东西才能真正得到第一个空白行:

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
于 2018-05-24T16:00:25.530 回答