查找两个工作簿之间的匹配项
我有两本数据工作簿。一个数据集是被拒绝的订单,另一个数据集是当前订单。我想知道我是否可以匹配订单,以便我可以利用拒绝文件中的订单。这样我就不必制作当前订单,同时可以减少被客户拒绝的订单堆。这是我的拒绝订单和当前/打印订单的数据表。 当前/已打印订单 这是被拒绝订单的数据表。 拒绝订单
我需要在三件事上匹配订单。首先,设计名称需要匹配,产品名称需要匹配,尺寸需要匹配,以获得“订单匹配”。
如何使用 Excel VBA 查找匹配项并在当前订单工作簿中创建一个新的 Excel 工作表,该工作表可以显示两个数据集之间匹配的订单。最终的数据输出将是订单号与两个文件中的订单号的对比。
我刚刚开始学习 vba,但这是一个我无法解决的复杂问题。请帮忙。我写了一段代码,但它无法运行。它说对象未定义。我写的代码是:
Sub Comparetwosheets()
Dim ws1 As Worksheet, ws2 As Worksheet Dim ws1row As Long、ws2row As Long、w1scol As Integer、ws2col As Integer 昏暗的报告作为工作表 Dim row As Long,col As Integer 调暗 R1 作为范围 Set R1 = Union(col(5), col(7), col(10))
Set reports = Worksheet.Add
'Set numrows = 数据行数
NumRows = Range("A1", Range("A1"). End(xlDown)).Rows.Count ' 选择单元格 a1。 范围(“A1”).选择 ' 建立“For”循环以循环“numrows”次。 对于 x = 1 到 NumRows x = 2 当 x < 时执行NonBlank
x = x + 1
Do While (ws1.R1 = ws2.R1)
If ws1.rw2 = ws2.rw2 Then
report.Cells(1, 1).Value = "Match"
Else: x = x + 1
Loop
Loop
'选择活动单元格下 1 行的单元格。 ActiveCell.Offset(1, 0).选择
结束子
I have two data workbooks. One dataset is of refused orders and the other dataset is for current orders. I want to find if i can match orders so that i can utilize the orders that I have in refused file. This way i wont have to make the current order and can simultaneously reduce my stack of orders that have been refused by customers. Here is my Data sheets for refused and current/printed orders.
Current/Printed Orders
Here is datasheet for the refused orders.
Refused Orders
I need to match orders on three things. First the design name needs to match, the product name needs to match and the size needs to match in order to get an "order match".
How can I use excel vba to find matches and create a new excel worksheet in the current order workbook that can show the orders that match between both data sets. The final data output would be order number against order number from both the files.
I am just beginning to learn vba but this is a complex problem that i can not solve. Please help. I wrote a code but it does not run. It says object not defined. Code that i wrote is :
Sub Comparetwosheets()
Dim ws1 As Worksheet, ws2 As Worksheet
Dim ws1row As Long, ws2row As Long, w1scol As Integer, ws2col As Integer
Dim report As Worksheet
Dim row As Long, col As Integer
Dim R1 As Range
Set R1 = Union(col(5), col(7), col(10))
Set report = Worksheet.Add
'Set numrows = number of rows of data
NumRows = Range("A1", Range("A1").End(xlDown)).Rows.Count
' Select cell a1.
Range("A1").Select
' Establish "For" loop to loop "numrows" number of times.
For x = 1 To NumRows
x = 2
Do While x < NonBlank
x = x + 1
Do While (ws1.R1 = ws2.R1)
If ws1.rw2 = ws2.rw2 Then
report.Cells(1, 1).Value = "Match"
Else: x = x + 1
Loop
Loop
'Selects cell down 1 row from active cell.
ActiveCell.Offset(1, 0).Select
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该可以为你做到。您可以将 CompareWorksheet 子例程中的以下变量设置为您需要的值(dataSet1、dataSet2、colPos1、colPos2、rowStart1、rowStart2)。我正在使用世界银行的随机数据集。


This should be able to do it for you. You are able to set the following variables in the CompareWorksheet subroutine to what you need then to be (dataSet1, dataSet2, colPos1, colPos2, rowStart1, rowStart2). I am using a random dataset from the world bank.

