Excel VLOOKUP使用string在文件中查找数据。 太慢了

这是我能得到的最好的。 成为任何人的search,并需要这种types的数据拉的最佳答案。 我不得不把它分解成几个部分; 这些工作计算机不能处理这种types的负载。 最大的数据拉动是大约800行,并需要大约一分钟拉动所有的公式和数据。 感谢下面的人们和他们的帮助。

Sub Update() Dim ScreenUpdateState As Boolean Dim StatusBarShow As Boolean Dim CalcState As Long Dim EventState As Boolean Dim ws As Worksheet Dim location_string As String Dim count As Integer 'Save the current state of Excel settings ScreenUpdateState = Application.ScreenUpdating StatusBarShow = Application.DisplayStatusBar CalcState = Application.Calculation EventState = Application.EnableEvents 'Change Excel to faster procedure settings Application.ScreenUpdating = False Application.DisplayStatusBar = False Application.Calculation = xlCalculationManual Application.EnableEvents = False ActiveSheet.DisplayPageBreaks = False Set ws = ThisWorkbook.Sheets("%") location_string = Sheets("Driver(s)").Cells(5, "G").Text For count = 7 To 139 Cells(count, "F").Formula = "=IFERROR((VLOOKUP($C" & count & ",'S:\xxxx\xxxxx\xxxxxx\xxxxx\xxxxxxxxxx\[xxxxxxxxxxxxxxxxxxxxxxxxxx.xlsx]" + location_string + "'!$A:$K,11,FALSE)),"" - "")" Next count 'Restore Excel settings to original state Application.ScreenUpdating = ScreenUpdateState Application.DisplayStatusBar = StatusBarShow Application.Calculation = CalcState Application.EnableEvents = EventState MsgBox ("Update Complete") End Sub 

祝你好运!

  • 罗斯

Orignal线程:

好吧,我现在有这个,它的工作原理。 然而,这个代码只能运行1/16的所需计算,需要几分钟的时间才能完成,所以速度慢。 任何人都知道加快这个过程的方法吗?

 Sub Test() Dim ws As Worksheet Dim location_string As String Dim count As Integer Set ws = ThisWorkbook.Sheets("%") location_string = ws.Cells(2, "E").Text count = 7 While count < 138 Cells(count, "F").Formula = "=IFERROR((VLOOKUP($C" & count & ", 'S:\xxxx\xxxx\xxxx\xxxx\xxxxx\[xxxxxx.xlsx]" + location_string + "'!$A:$K,11,FALSE)),"" - "")" count = count + 1 Wend MsgBox ("Done") End Sub 

以下是原文:

我有另一个表中的值的列表,将创build我需要的string的一部分:

 =CONCATENATE ((INDEX('Driver(s)'!$B$1:$B$48,'Driver(s)'!$G$3,1)),"Epic") 

这将设置一个单元格='O614Epic

现在试图添加一个Vlookup从拉:

 S:\xxxxxxxxxxxxxxx\xxxxxxxxx\xx\xx\xx\[Random File Name.xlsx]0614Epic'!$A:$K 

根据下拉框,#### Epic文件将会以string的forms更改为正确的值,但无法从正确的工作簿中获取Vlookup。 我也需要这个打开未打开的工作簿。 太多的数据导入Excel工作簿本身。

谢谢。

  • 罗斯

如果没有使用VLOOKUP,请跳到奖励信息。 而不是让VLOOKUP公式重新计算每个更改并放慢您的电子表格,您可以使用VBA查找并将值放入单元格而不是公式。 我尽最大努力量身定做。 如果您对任何部件有任何疑问,请告诉我们。

 Function WorksheetExists(ByVal WorksheetName As String) As Boolean Dim Sht As Worksheet For Each Sht In ActiveWorkbook.Worksheets If Application.Proper(Sht.Name) = Application.Proper(WorksheetName) Then WorksheetExists = True Exit Function End If Next Sht End Function Sub RossQuestion() Dim wbdata As Workbook Dim ws As Worksheet Dim Cell As Range Dim location_string As String Dim strcheck As String Dim count As Integer Set ws = ThisWorkbook.Sheets("%") location_string = ws.Cells(2, "E").Text count = 7 While count < 138 Set wbdata = Workbooks.Open("S:\xxxx\xxxx\xxxx\xxxx\xxxxx\xxxxxx.xlsx", , True) If WorksheetExists(location_string) Then Set Cell = wbdata.Sheets(location_string).Columns("A").Find(ws.Range("$C$" & count).Value, _ wbdata.Sheets(location_string).Range("A1"), xlFormulas, xlWhole, xlByRows, xlNext, False) strcheck = Cell.Offset(0, 10).Value If Len(Trim(strcheck)) <> 0 Then ws.Cells(count, "F").Value = Cell.Offset(0, 10).Value Else ws.Cells(count, "F").Value = " - " End If Else ws.Cells(count, "F").Value = " - " End If count = count + 1 wbdata.Close False Wend MsgBox "Done" End Sub 

奖金信息:

如果你不打包你的代码这样的事情,考虑使用这个为所有未来的VBA。 这个链接的第一个提示详细说明了这些操作。

 Dim ScreenUpdateState As Boolean Dim StatusBarShow As Boolean Dim CalcState As Long Dim EventState As Boolean 'Save the current state of Excel settings ScreenUpdateState = Application.ScreenUpdating StatusBarShow = Application.DisplayStatusBar CalcState = Application.Calculation EventState = Application.EnableEvents 'Change Excel to faster procedure settings Application.ScreenUpdating = False Application.DisplayStatusBar = False Application.Calculation = xlCalculationManual Application.EnableEvents = False ActiveSheet.DisplayPageBreaks = False '<<<YOUR CODE HERE>>> 'Restore Excel settings to original state Application.ScreenUpdating = ScreenUpdateState Application.DisplayStatusBar = StatusBarShow Application.Calculation = CalcState Application.EnableEvents = EventState 

原始答案:

虽然您可以从其他工作簿(甚至未打开)中引用数据,但您的VLOOKUP的table_array参数中的path必须完全键入。

所以,虽然VLOOKUP接受…

 =VLOOKUP('Driver(s)'!$G$3, 'S:\xxxxx\FileName.xlsx'!$A:$K, 3, FALSE) 

它不会接受table_array中的任何计算或连接,例如…

 =VLOOKUP('Driver(s)'!$G$3, 'S:\xxxxx\ & O614Epic & .xlsx'!$A:$K, 3, FALSE) =VLOOKUP('Driver(s)'!$G$3, 'S:\xxxxx\ & INDIRECT(B1) & Epic.xlsx'!$A:$K, 3, FALSE) 

除了完整的pathstring以外的任何内容都被认为太易变。 MATCH INDEX也一样。 不幸的是,VLOOKUP不像你想要的那样dynamic,#### Epic需要被你input为O614Epic,而不是来自另一个单元格。

总是有VBA。 一切都可能与VBA。

删除循环,试试这个:

 Sub Test() Dim ws As Worksheet Dim location_string As String Dim myformula As String With Application .ScreenUpdating = False .DisplayAlerts = False End With Set ws = ThisWorkbook.Sheets("%") location_string = ws.Cells(2, "E").Value '~~> I'd suggest you use Value myformula = "=IFERROR((VLOOKUP($C7,'S:\xxxx\xxxx\xxxx\xxxx\xxxxx\[xxxxxx.xlsx]" & _ location_string & "'!$A:$K,11,FALSE)),"" - "")" Range("F7:F138").Formula = myformula Msgbox "Done" With Application .ScreenUpdating = True .DisplayAlerts = True End With End Sub 

这在我的机器上需要5秒钟,但是如果目标文件在networking服务器中,它将会有所不同。 HTH。