小编cod*_*cha的帖子

VBA:查找功能代码

我试图通过vba中的find函数进行vlookup.我在贷款表和财产表中有一个数字列表,如果在贷款表中找到了这个数字,那么它会复制整行并将其粘贴到另一个名为查询的表中.这是我目前的代码,但代码只是挂起,因为我有太多的单元格可以找到大约100,000.对代码中的任何错误的任何指导都会非常有用.

Option Explicit
Sub FindCopy_lall()

Dim calc As Long
Dim Cel As Range
Dim LastRow As Long
Dim LastRow2 As Long
Dim rFound As Range
Dim LookRange As Range
Dim CelValue As Variant
 ' Speed
calc = Application.Calculation
With Application
    .Calculation = xlCalculationManual
    .ScreenUpdating = False
End With
 'Get Last row of Property SheetColumn
LastRow = Worksheets("Property").Cells(Rows.Count, "E").End(xlUp).Row
LastRow2 = Worksheets("Loan").Cells(Rows.Count, "D").End(xlUp).Row

 ' Set range to look in
Set LookRange = Worksheets("Property").Range("E2:E" & LastRow)
 ' Loop on each value (cell) …
Run Code Online (Sandbox Code Playgroud)

performance vba find

1
推荐指数
1
解决办法
3076
查看次数

VLookup多列

我正在使用VLookup函数,它查找列中存在的多个值.这非常有效,但只需要花费很多时间,因为我在Excel工作表中有100,000行.

有没有办法加快这个代码?

代码基本上在列中查找特定值并获取偏移量.简单的VLookup与此之间的区别在于,如果有多个行具有相同的查找值,则它将获取所有元素.

   Function VLookupAll(ByVal lookup_value As String, _
                ByVal lookup_column As Range, _
                ByVal return_value_column As Long, _
                Optional seperator As String = ", ") As String

 Dim i As Long
 Dim result As String

For i = 1 To lookup_column.Rows.Count
If Len(lookup_column(i, 1).Text) <> 0 Then
    If lookup_column(i, 1).Text = lookup_value Then
        result = result & (lookup_column(i).Offset(0, return_value_column).Text & seperator)
    End If
End If
Next

If Len(result) <> 0 Then
result = Left(result, Len(result) - Len(seperator))
End If …
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba vlookup

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

vba ×2

excel ×1

excel-vba ×1

find ×1

performance ×1

vlookup ×1