在Tab" FISV 03-05"我在C列中有值。我想在选项卡的C列中查找相同的值" PF Outstandings"并将D列的值返回到" FISV 03-05"的D列;标签。它必须完全匹配,我有超过250K行的数据来查找值(在Excel中使用vlookup公式需要超过20分钟)
有没有在VBA中进行此vlookup所以需要更少的时间? C列和D列中的每个值都是唯一的
FISV 03-05 tab:
Column C Column D
2627-503 Value to be returned
PF Outstandings Tab:
Column C Column D
2627-503 PF-05-03
答案 0 :(得分:1)
你不需要VBA:
如果您可以对Lookup表进行排序,那么您可以使用快速闪电的Double VLOOKUP技巧。 这涉及使用如下公式:在' FISV 02-5'!$ D2
import UIKit
@IBDesignable
class TopView: UIView {
//MARK:- IB Outlets
var contentView:UIView?
//MARK:- Lifecycle
override func awakeFromNib() {
super.awakeFromNib()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupThisView()
}
override init(frame: CGRect) {
super.init(frame: frame)
setupThisView()
}
override func prepareForInterfaceBuilder() {
super.prepareForInterfaceBuilder()
setupThisView()
contentView?.prepareForInterfaceBuilder()
}
//MARK:- Lifecycle methods
private func setupThisView(){
guard let view = loadViewFromNib() else { return }
view.frame = bounds
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
addSubview(view)
contentView = view
}
func loadViewFromNib() -> UIView? {
let nibName = String(describing: TopView.self)
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: nibName, bundle: bundle)
return nib.instantiate(withOwner: self,options: nil).first as? UIView
}
}
有关详细信息,请参阅我的博文 https://fastexcel.wordpress.com/2012/03/29/vlookup-tricks-why-2-vlookups-are-better-than-1-vlookup/
答案 1 :(得分:1)
这可能很快:
Sub fastVlookup()
Dim i As Long
Dim lookUpDict As Scripting.Dictionary
Set lookUpDict = CreateObject("Scripting.Dictionary")
Dim lookUpData As Variant
Dim sourceData As Variant
With Worksheets("FISV 03-05")
sourceData = .Range("D1", .Cells(.Rows.Count, 3).End(xlUp)).value
End With
With Worksheets("PF Outstandings")
lookUpData = .Range("D1", .Cells(.Rows.Count, 3).End(xlUp)).value
End With
With lookUpDict
For i = 1 To UBound(lookUpData)
.Add lookUpData(i, 1), lookUpData(i, 2)
Next
For i = 1 To UBound(sourceData)
sourceData(i, 2) = .Item(sourceData(i, 1))
Next
End With
Worksheets("FISV 03-05").Range("C1:D1").Resize(UBound(sourceData)).value = sourceData
End Sub
它需要将“Microsoft Scripting Runtime”库引用添加到您的项目中(在VBA IDE中,单击Tools-> References,将列表框向下滚动到“Microsoft Scripting Runtime”项,选中它并单击OK)