需要VBA宏帮助

发布于 2025-02-13 21:36:33 字数 393 浏览 0 评论 0原文

我目前正在研究一个涉及选项链的项目,我需要每五分钟和同一列中的同一本书中的单个单元格将值从单个单元格复制到另一个单元格。但是,由于我对VBA的不熟悉,这是我可以做的最好的宏,而且效率很低:

Sub Macro1()
    Sheets("Sheet1").Select
    Range("A1").Copy
    Sheets("Sheet2").Select
    ActiveSheet.PasteSpecial Paste:=xlPasteValues
    ActiveCell.Offset(1, 0).Select
    Sheets("Sheet1").Select
End Sub

注意:A1是占位符,目前我正在处理信息粘贴,而不是5分钟的计时器。

我如何改善宏?

I'm currently working on a project involving option chains and I need to copy the value from a single cell to another sheet in the same book every five minutes, and in the same column. However, due to my unfamiliarity with VBA this is the best macro I could make, and it's very inefficient:

Sub Macro1()
    Sheets("Sheet1").Select
    Range("A1").Copy
    Sheets("Sheet2").Select
    ActiveSheet.PasteSpecial Paste:=xlPasteValues
    ActiveCell.Offset(1, 0).Select
    Sheets("Sheet1").Select
End Sub

Note: A1 is a placeholder, and I'm currently dealing with the information pasting, not the 5 minute timer.

How could I improve the macro?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

逆流 2025-02-20 21:36:33

尝试-

Sub Macro1()
Dim ws As Worksheet
Dim lrow As Long

    Set ws = Worksheets("Sheet2")
    lrow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row + 1
    ws.Range("A" & lrow) = Sheets("Sheet1").Range("A1").Value2
    
    Set ws = Nothing
End Sub

Try-

Sub Macro1()
Dim ws As Worksheet
Dim lrow As Long

    Set ws = Worksheets("Sheet2")
    lrow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row + 1
    ws.Range("A" & lrow) = Sheets("Sheet1").Range("A1").Value2
    
    Set ws = Nothing
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文