Sorry for doing it wrong.@PietBom
We ask that you answer the question within the thread itself"
Function ZoekBinair(Zoek As String, Reeks As Range)
n_Codes = Reeks.Rows.Count
n_Checks = Int(1 + Log(n_Codes) / Log(2)) + 1
x = Int(n_Codes / 2 + 0.5)
Stap = x
Gevonden = "No"
For Z = 1 To n_Checks
If StrComp(Zoek, Reeks.Cells(x, 1).Value, vbTextCompare) = 0 Then
Gevonden = "Yes"
GoTo Uit1
End If
Stap = Int(Stap / 2 + 0.5)
If Stap < 1 Then Stap = 1
If StrComp(Zoek, Reeks.Cells(x, 1).Value, vbTextCompare) = -1 Then
x = x - Stap
If x <= 1 Then x = 1
End If
If StrComp(Zoek, Reeks.Cells(x, 1).Value, vbTextCompare) = 1 Then
x = x + Stap
If x >= n_Codes Then x = n_Codes
End If
Next Z
Uit1:
ZoekBinair = -999
If Gevonden = "Yes" Then ZoekBinair = x
End Function
Function ZoekBinair(Zoek As String, Reeks As Range)
n_Codes = Reeks.Rows.Count
n_Checks = Int(1 + Log(n_Codes) / Log(2)) + 1
x = Int(n_Codes / 2 + 0.5)
Stap = x
Gevonden = "No"
For Z = 1 To n_Checks
[COLOR=#ff0000]search_result[/COLOR] = StrComp(Zoek, Reeks.Cells(x, 1).Value, vbTextCompare)
If search_result = 0 Then
Gevonden = "Yes"
GoTo Uit1
End If
Stap = Int(Stap / 2 + 0.5)
If Stap < 1 Then Stap = 1
If search_result = -1 Then
x = x - Stap
If x <= 1 Then x = 1
End If
If search_result = 1 Then
x = x + Stap
If x >= n_Codes Then x = n_Codes
End If
Next Z
Uit1:
ZoekBinair = -999
If Gevonden = "Yes" Then ZoekBinair = x
End Function
Sub testlookup()
Dim lastrow, lastrow2, i As Long
Dim Searchfor, j, inarr As Variant
'Data Dump Sheet
With Sheets("Sheet 2")
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
inarr = Range(.Cells(1, 1), .Cells(lastrow, 20))
End With
'Values to look up & paste Sheet
With Sheets("Sheet 1")
lastrow2 = .Cells(Rows.Count, "B").End(xlUp).Row
' load variant array with sercha variables
searcharr = Range(.Cells(1, 2), .Cells(lastrow2, 2))
' define an output aray
outarr = Range(.Cells(2, 3), .Cells(lastrow2, 19))
End With
On Error Resume Next
For i = 2 To lastrow2
For j = 2 To lastrow
Searchfor = searcharr(i, 1)
If inarr(j, 1) = Searchfor Then
For kk = 2 To 18
outarr(i, kk - 1) = inarr(j, kk)
Exit For
End If
Next j
Next i
' writeout the output array
With Sheets("Sheet 1")
Range(.Cells(2, 3), .Cells(lastrow2, 19)) = outarr
End With
End Sub
Function ZoekBinair(Zoek As String, Reeks As Range)
Dim inarr As Variant
n_Codes = Reeks.Rows.Count
inarr = Reeks.Value
n_Checks = Int(1 + Log(n_Codes) / Log(2)) + 1
x = Int(n_Codes / 2 + 0.5)
Stap = x
Gevonden = "No"
For Z = 1 To n_Checks
search_result = StrComp(Zoek, inarr(x, 1), vbTextCompare)
If search_result = 0 Then
Gevonden = "Yes"
GoTo Uit1
End If
Stap = Int(Stap / 2 + 0.5)
If Stap < 1 Then Stap = 1
If search_result = -1 Then
x = x - Stap
If x <= 1 Then x = 1
End If
If search_result = 1 Then
x = x + Stap
If x >= n_Codes Then x = n_Codes
End If
Next Z
Uit1:
ZoekBinair = -999
If Gevonden = "Yes" Then ZoekBinair = x
End Function