简体   繁体   English

将数据范围复制和粘贴到特定日期单元格

[英]Copying and Pasting Range of Data to specific date cells

I have this code which works and is awesome however it can only find the current date we are in (because of DateValue (now)) I would like this to be set off a cell value instead on the "Input" Worksheet (Cell D4) in particular. 我有此代码,该代码有效并且很棒,但是它只能找到我们所在的当前日期(由于DateValue(现在)),我希望将其设置为单元格值,而不是在“输入”工作表上(单元格D4)尤其是。

Anyone know how? 有人知道吗?

Sub FindToday()

Dim FoundDate As Range
Set FoundDate = Worksheets("Data").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("Input").Range("A4:H4").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

Thanks all 谢谢大家

here's one that pops up an input box so you can choose to alter the target date from now a number of days: like, enter -3 and it puts the data in for 3 days ago... is something like this what you were looking for? 这里有一个弹出一个输入框,所以你可以选择从现在的天数改变目标日期:喜欢,进入-3,它把数据在3天前...是这样的你要找对于? Or did you want it to copy all new data? 还是您要它复制所有新数据? or just all data regardless of date? 还是仅仅是所有数据,而不考虑日期?

Sub FindToday()
Dim N As Long
Dim FoundDate As Range
N = Application.InputBox("Enter Date Offset:", "Date Selector")
If N = False Then Exit Sub
Set FoundDate = Worksheets("Data").Columns("A").Find(DateValue(Now + N), LookIn:=xlValues, lookat:=xlWhole)

If Not FoundDate Is Nothing Then ' if we don't find the date, simply skip.
    Worksheets("Input").Range("A4:H4").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

Just use a range instead: 只需使用范围即可:

Sub FindToday()
Dim searchDate as Range

Dim FoundDate As Range
Set searchDate = Worksheets("Input").Range("D4")
Set FoundDate = Worksheets("Data").Columns("A").Find(searchDate.Value, LookIn:=xlValues, lookat:=xlWhole)

If Not FoundDate Is Nothing Then ' if we don't find the date, simply skip.
    Worksheets("Input").Range("A4:H4").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

Or maybe you would do ...Find(DateValue(searchDate.value)... 或者,也许您会...Find(DateValue(searchDate.value)...

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

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