简体   繁体   English

复制和粘贴列最后一行的最后数据的功能

[英]Function to copy and paste the last data of the last row of a column

below is my code on copying and pasting the data of the last row of a column. 下面是我关于复制和粘贴列最后一行数据的代码。 it works on the command button but if i make it as a function, it's not working. 它可以在命令按钮上工作,但是如果我将其作为功能使用,它将无法正常工作。 it gives a 0 or false result. 结果为0或错误。 please check. 请检查。 thanks. 谢谢。

    Function CopyCell()

    Application.Volatile True
    Dim eRow As Integer
    Dim i As Integer

    With Sheets("Weekly Score")
    eRow = .Cells(Rows.Count, "N").End(xlUp).Row
    .Cells(eRow, "N").Copy
    .Range("AG3").PasteSpecial xlPasteValues
    End With

    ENd Function

Try doing this assign a MyFunction to your button 尝试执行此操作为按钮分配MyFunction

Option Explicit
Sub MyFunction()
   Call CopyCell
End Sub

Function CopyCell()
Application.Volatile True
    Dim eRow    As Integer
    Dim i       As Integer

    With Sheets("Weekly Score")
        eRow = .Cells(Rows.count, "N").End(xlUp).Row
        .Cells(eRow, "N").copy
        .Range("AG3").PasteSpecial xlPasteValues
    End With

End Function

If you want an UDF modify the function as such: 如果要UDF修改功能,如下所示:

Public Function CopyCell()
    Application.Volatile True
    Dim eRow As Integer
    Dim i As Integer

    With Sheets("Weekly Score")
      eRow = .Cells(Rows.Count, "N").End(xlUp).Row
      CopyCell =  .Cells(eRow, "N").Value
    End With
End Function

Otherwise lose the Volatile and change the Function to a `Sub and simply call it manually: 否则,将失去Volatile并将Function更改为`Sub并简单地手动调用它:

Sub CopyCell()

    Dim eRow As Integer
    Dim i As Integer

    With Sheets("Weekly Score")
     eRow = .Cells(Rows.Count, "N").End(xlUp).Row
     .Cells(eRow, "N").Copy
     .Range("AG3").PasteSpecial xlPasteValues
    End With
End Sub

Remember that Application.Volatile True will cause the function to recalculate whenever any Calculation is carried out. 请记住,只要执行任何计算, Application.Volatile True都会导致函数重新计算。 This may seriously impact performance. 这可能会严重影响性能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM