Hello,
I'm having troubles searching through an array.
I'm either getting a Mismatch or "unable to get the match property of..." error no matter what I try.
I'm I deeply misunderstanding something?
I'm trying to check if a value (string) appears further down the data-set, and if so print the adjacent values to the hit and the search value to a different sheet.
If the string does appear, and the adjacent value is the same as the search value - don't want to print.
If the string appears several times, I want the adjacent values of the next ones to print into the next column of the same "string".
This might not be the best way to comb through, If you have any suggestions I'm more than willing to try them.
Thank you for your time
Sincerely,
Kasper
I'm having troubles searching through an array.
I'm either getting a Mismatch or "unable to get the match property of..." error no matter what I try.
I'm I deeply misunderstanding something?
I'm trying to check if a value (string) appears further down the data-set, and if so print the adjacent values to the hit and the search value to a different sheet.
If the string does appear, and the adjacent value is the same as the search value - don't want to print.
If the string appears several times, I want the adjacent values of the next ones to print into the next column of the same "string".
This might not be the best way to comb through, If you have any suggestions I'm more than willing to try them.
VBA Code:
Sub MREXCEL()
Dim ws As Worksheet
Dim wso As Worksheet
Dim wb As Workbook
Dim r
Dim a, b, c
Dim i As Long, LRow As Long, LRowo As Long, y As Long
Dim Søk As String, Søkr As String, Retur As String
Dim Returnr As Long
Dim Arr() As Variant
Dim Match As String
Set wb = Excel.Workbooks("test.xlsm")
Set ws = wb.Worksheets("Sheet2")
Set wso = wb.Worksheets("Sheet3")
LRow = ws.Cells(Rows.Count, 1).End(xlUp).Row
LRowo = wso.Cells(Rows.Count, 1).End(xlUp).Row
a = Range(ws.Cells(1, 1), ws.Cells(LRow, 1)).Resize(, 7)
ReDim r(1 To UBound(a, 1))
For y = 1 To UBound(a, 1)
r(y) = a(y, 1)
Next y
For i = 2 To UBound(a)
Søkr = a(i, 3)
x = i + 1
Do While x < LRow + 1
r = Range(ws.Cells(x, 3), ws.Cells(LRow, 1))
If Not IsError(Application.WorksheetFunction.Match(Søkr, r, 0)) Then '//The error appears at this very first Match function.
Match = Application.WorksheetFunction.Match(Søkr, r, 0)
If Not a(i, 4) = a(Match, 2) Then
If IsError(Application.WorksheetFunction.Match(Søkr, Range(wso.Cells(1, 1), wso.Cells(LRowo, 1)), 0)) Then
wso.Cells(LRowo, 1) = a(i, 1)
wso.Cells(LRowo, 2) = a(i, 3)
wso.Cells(LRowo, 3) = a(Match, 1)
LRowo = wso.Cells(Rows.Count, 1).End(xlUp).Row
Else
Matcho = Application.WorksheetFunction.Match(Søkr, Range(wso.Cells(1, 1), wso.Cells(LRowo, 1)), 0)
wso.Cells(Matcho, 1).End(xlToLeft) = a(Match, 1)
End If
Else
x = Match + 1
End If
End If
Loop
Next i
End Sub
Thank you for your time
Sincerely,
Kasper