我目前有两个50k +行的文件。 它们都包含订单代码。在一个文件中是正确的(" AQ列",7),另一个文件在C列中。 我想匹配订单代码,并比较值是否相同。此外,在第二个文件中,应该检查不同的列以查看是否存在匹配的字符串" SETTLED"因为该文件中有重复的订单代码。
我已经尝试了一些方法,我在下面粘贴一个效率不高的方法,以便我想要解决的问题要清楚。 revnW和Wpay是两种不同的工作簿
DesLRow = revnW.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
SrcLRow = wPay.Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 to DesLrow
for j = 3 to srcLrow
If right(revnW.Sheets(1).Cells(i,43).text, 7) = wPay.Sheets(1).Cells(j,3).text And_
Instr(wPay.Sheets(1).Cells(j,5).text, "SETTLED") And value <> value 2 (pseudo code) Then
Do stuff (get transaction number, and some other things)
exit for
next j
Next i
我知道这段代码效率不高,我试图将列加载到数组中,但后来我只能比较一列,而不是值等。
非常感谢任何帮助。
答案 0 :(得分:0)
我会用一些SQL处理数据。 这是一个在第三个表中连接两个表的示例:
var express = require('express');
var app = express();
// Users routes
var users = require('./routes/users');
// Tell our app to use the Users routes defined in ./routes/users.js
app.use('/users', users);
app.listen(process.env.PORT || 3000, function() {
console.log('listening');
});
答案 1 :(得分:0)
未经测试,但应该给你一个起点:
Sub Tester()
Dim desLRow As Long, srcLRow As Long
Dim dictDest As Object, dictSrc As Object
With revnW.Sheets(1)
Set dictDest = RowMap(.Range(.Cells(2, 43), .Cells(.Rows.Count, 43).End(xlUp)), 7)
End With
With wPay.Sheets(1)
Set dictSrc = RowMap(.Range(.Cells(3, 3), .Cells(.Rows.Count, 3).End(xlUp)))
End With
For Each k In dictDest.keys
If dictSrc.exists(k) Then
'do the rest of your checks here....
Debug.Print "Match between Dest " & dictDest(k).Address & " and " & _
dictSrc(k).Address
End If
Next k
End Sub
这是“地图”功能:
'Get a "map" of row keys to the
' rows where they are located (just maps the first cell in each row)
' "rng" is the range to be mapped
' "numright" - pass a number if you just want a part of the value to be mapped
Function RowMap(rng As Range, Optional numRight As Long = 0)
Dim rv, nr As Long, nc As Long, r As Long, c As Long
Dim k, data
Set rv = CreateObject("scripting.dictionary")
data = rng.Value
For r = 1 To UBound(data, 1)
k = data(r, 1)
If numRight > 0 Then k = Right(k, numRight)
If rv.exists(k) Then
Set rv(k) = Application.Union(rv(k), rng.Columns(1).Cells(r))
Else
rv.Add k, rng.Columns(1).Cells(r)
End If
Next r
Set RowMap = rv
End Function