简体   繁体   English

VBA比较两个日期,然后将数据从一张纸传输到新纸和相关列

[英]VBA to compare two dates then transfer data from one sheet to new sheet and relevant column

I have spent the past few days to a week browsing the net, and whilst I have come close to what I am looking for, with all due respect meant - me being a novice and all that, there seems to be a lot of code around but seems somewhat of an over kill to what I need. 在过去的几天里,我花了一周的时间浏览网络,尽管我已经接近了我要寻找的内容,但应有的充分敬意-我是新手,所有这些似乎都有很多代码但似乎有点超出我的需求。 So now, because I can't actually find what it is I am looking for, and whilst learning a few new things at the same time, I am now posting my question to see if I can find my answer. 所以现在,因为我实际上找不到我想要的东西,并且在同时学习一些新知识的同时,我现在发布我的问题以查看是否可以找到答案。

Putting a side all in-cell If and vlookup statements - and so on, I have got pretty far in a project that I am working on, but have hit one small snag to complete it. 将所有单元内If和vlookup语句放在一边-依此类推,我在我正在从事的项目中已经走了很远,但遇到了一个小小的障碍就可以完成它。

From initial data input to Macro's that do collect data in one sheet, then after print - harvests this data and then sorts in to a new order within a "Transfer" Sheet ready to move to the last sheet. 从最初的数据输入到在一张纸中收集数据的Macro's,然后在打印后-收集这些数据,然后在“转移”纸中分类为新的顺序,准备移至最后一张纸。

Bridging a gap! 弥合差距!

After doing everything so far myself, I need to be able to get one small piece of code together that now accesses the "Transfer" sheet, finds the date ("B6" [eg June-16]) and matches it against a corresponding one in another sheet "Annual" in row("B6:M6" [Jan-16:Dec-16]); 在自己完成到目前为止的所有工作之后,我需要能够将一小段代码放在一起,现在可以访问“ Transfer”工作表,找到日期(“ B6” [例如6月16日])并将其与相应的日期进行匹配在另一张表格中的“年度”行中(“ B6:M6” [Jan-16:Dec-16]); the result would be; 结果是;

Sub: lookup "Transfer"("B6")="Annual"("G6"), copy content "Transfer"("B9:B128"), paste "Annual"(G9:G128"). End 子:查找“ Transfer”(“ B6”)=“ Annual”(“ G6”),复制内容“ Transfer”(“ B9:B128”),粘贴“ Annual”(G9:G128“)。结束

However, I think some of my problem is based on the level of automation the workbook is working on, for example: Transfer (B6) and Annual (B6:K6) dates are based on differing formulas (variables) resulting in the same (values [Jun-16 // mmm-yy) 但是,我认为我的一些问题是基于工作簿正在处理的自动化程度,例如:转移(B6)和年度(B6:K6)日期是基于不同的公式(变量)得出相同的(值) [16年6月// // mmm-yy)

Your help would be greatly appreciated 您的帮助将不胜感激

JohnH 约翰·H

John, please try the following: 约翰,请尝试以下操作:

Sub copyToTransfer()

Dim rng As Range
Dim rngSource As Range
Dim rngTarget As Range

Set rngSource = ThisWorkbook.Sheets("Transfer").Range("B6")
Set rngTarget = ThisWorkbook.Sheets("Annual").Rows(6)

Set rng = rngTarget.Find(rngSource.Value, , xlValues)

If Not rng Is Nothing Then
    ThisWorkbook.Sheets(rngSource.Parent.Name).Range(rngSource.Offset(3).Address, rngSource.Offset(125).Address).Copy
    rng.Offset(3).PasteSpecial xlPasteAll
    Application.CutCopyMode = False
Else
    MsgBox "Date " & Format(rngSource.Value, "mmm-yy") & " not found in Annual sheet!"
End If

End Sub 结束子

Whilst Markos answer has been of some help, and it works to a point of completing its cycle without error, it seems there could well be a issue hidden, so whilst I don't want badger him too much, I suspect it relates to one of two places; 虽然Markos的回答有所帮助,并且可以顺利完成其循环,但似乎存在隐藏的问题,因此尽管我不想过多地whilst他,但我怀疑这与一个问题有关在两个地方;

Set rngTarget = ThisWorkbook.Sheets("Annual").Rows(6) 设置rngTarget = ThisWorkbook.Sheets(“ Annual”)。Rows(6)

Set rng = rngTarget.Find(rngSource.Value, , xlValues) 设置rng = rngTarget.Find(rngSource.Value`` xlValues)

Whilst I could be wrong, the reason for this understanding is, that I have created three different workbooks, 1. as 97-03 version, 2. a plain 07 version and 3. 07-macro enabled version and all tests come back as; 尽管我可能是错的,但这种理解的原因是,我创建了三个不同的工作簿:1.作为97-03版本,2。一个普通的07版本和3.启用07-宏的版本,所有测试都返回为; It finds its source and recognizes the date, but when looking at its target, it is staring at a blank page! 它找到其来源并识别日期,但是在查看目标时,它盯着空白页! Is there anyone else that would like to contribute, or are able to identify the issue? 是否还有其他人愿意做出贡献或能够确定问题所在?

John 约翰

暂无
暂无

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

相关问题 VBA将数据从一张纸传输到另一张纸 - VBA Transfer of data from one sheet to another 比较两张 excel 工作表,以了解来自工作表 1 的工作表 2 中的缺失数据和新数据 - Compare two excel sheets for missing and new data in Sheet 2 from Sheet 1 一列二 function,并将数据传输到下一张 - One column two function, and transfer data to next sheet 将数据从工作表传输到另一工作表的 VBA 代码 - A VBA code to transfer data from a sheet to another one VBA-根据文本将数据从一张纸传输到另一张纸,然后放入另一张纸的特定位置 - VBA- Transfer data from one sheet to another based on text and placing in into a specific location in the other sheet 将数据传输到新工作表 - Transfer data to new sheet 将数据从一张工作表上的两个单元格传输到同一 Excel 工作簿中不同工作表上的两个单元格 - Transfer data from two cells on one sheet to two cells on a different sheet in the same Excel workbook Excel VBA:我试图将具有某种条件的sheets1中的数据与sheet2中的数据进行比较,并且仅将不匹配的数据传输到sheet2中 - Excel VBA: Im trying to compare data from sheets1 with some condition to data in sheet2 and transfer only unmatched data to sheet2 计数并转移到新的工作表VBA - Count and transfer to new sheet VBA Excel比较一张工作表中的两列,将匹配的整个行复制到新工作表中 - Excel compare two columns from one sheet copy entire row on match to new sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM