Excel/VBA - 根据日期将数据复制并粘贴到工作表中的特定行中

发布于 2024-11-29 01:23:24 字数 362 浏览 0 评论 0原文

我有一个我认为非常简单的问题。

我有一份每天更新的报告。每天需要将一个工作表中的特定范围 (B5:AC5) 复制到不同的工作表中。这不需要自动完成,我只想将其代码添加到我创建的格式化宏中。

我对此有两个问题:

  1. 我希望将数据粘贴到与该特定日期对应的行中。工作表“每日”中的 A 列包含该月的工作日列表。所以我需要的只是让宏在“每日”的 A 列中找到今天的日期,然后将“矩阵”中的 b5:AC5 粘贴到 b?:ac? 中。在“每日”的该行中。

  2. 我还需要它是特殊粘贴,仅粘贴值。

我对 VB 很陌生,但通常可以很好地遵循代码逻辑。如果您需要我提供更多信息,请告诉我。太感谢了!

I have what I think is a pretty simple question.

I have a report that is updated daily. A specific range (B5:AC5) from one worksheet needs to be copied to a different worksheet on a daily basis. This doesn't need to be done automatically, I'd just like to add the code for it into a formatting macro I've created.

I have two issues with this:

  1. I want the data to be pasted in the row that corresponds with that specific day. Column A in worksheet "Daily" has the list of working days for that month. So all I need is for the macro to find today's date in Column A in "Daily", and paste b5:AC5 from "Matrix" in b?:ac? in that row on "Daily".

  2. I also need it to be a paste special, with only the values being pasted.

I'm very new to VB, but can usually follow code logic pretty well. Let me know if you need any more information from me. Thank you so much!

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

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

发布评论

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

评论(1

‘画卷フ 2024-12-06 01:23:24

假设你的范围总是在 B5:AC5,这就是我的想法:

Sub FindToday()

    Dim FoundDate As Range
    Set FoundDate = Worksheets("Daily").Columns("A").Find(DateValue(Now), LookIn:=xlValues, lookat:=xlWhole)

    If Not FoundDate Is Nothing Then ' if we don't find the date, simply skip. 
        Worksheets("Matrix").Range("B5:AC5").Copy
        FoundDate.Offset(0, 1).PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, False, False ' You can see that the first argument in PasteSpecial is set to only paste values. 

   End If
End Sub

我根据你的信息尽我所能测试了这一点。我在 B5:AC5 范围内放置了一组升序数字,并使用公式,在每日工作表中放置了一个月的一组升序日期,它似乎可以满足您的要求。

希望这有帮助。

Assuming that your range will always be in B5:AC5, here is what I came up with:

Sub FindToday()

    Dim FoundDate As Range
    Set FoundDate = Worksheets("Daily").Columns("A").Find(DateValue(Now), LookIn:=xlValues, lookat:=xlWhole)

    If Not FoundDate Is Nothing Then ' if we don't find the date, simply skip. 
        Worksheets("Matrix").Range("B5:AC5").Copy
        FoundDate.Offset(0, 1).PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, False, False ' You can see that the first argument in PasteSpecial is set to only paste values. 

   End If
End Sub

I tested this as best I could given your information. I put a set of ascending numbers in the B5:AC5 range, with formulas, put a set of ascending dates for one month in the Daily sheet, and it seems to do what you're looking for.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文