Offset after first match until the first occurrence of a given string

Bering

Board Regular
Joined
Aug 22, 2018
Messages
185
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have uploaded an image of my data and the expected result highlighted in yellow.

My goal is to match ABC (or BCE, CDE etc), then offset until the first occurrence of the string "swift" is found below and get the corresponding value in column D.

No luck so far.

Thank you.
 

Attachments

  • Help.JPG
    Help.JPG
    50.9 KB · Views: 7

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Apologies, there was a mistake in the first image, please refer to the one attached here.
 

Attachments

  • HelpNew.JPG
    HelpNew.JPG
    53.9 KB · Views: 7
Upvote 0
Are you still using version 2016? You can try something like this.
Edit: Didn't notice your EFG would only have 2 rows. Inconsistent with the others. This won't work.
Book2
ABCDEFGH
1
2
3ABCABC123
4IBANBCE345
5swift123CDE222
6
7BCE
8IBAN
9swift345
10
11CDE
12IBAN
13swift222
14
Sheet3
Cell Formulas
RangeFormula
F3:F5F3=OFFSET($C$3,(ROWS($C$3:C3)-1)*4,0)
G3:G5G3=INDEX($D$3:$D$13,MATCH(F3,$C$3:$C$13,0)+2)
 
Last edited:
Upvote 0
Are you still using version 2016? You can try something like this.

Book2
ABCDEFGH
1
2
3ABCABC123
4IBANBCE345
5swift123CDE222
6
7BCE
8IBAN
9swift345
10
11CDE
12IBAN
13swift222
14
Sheet3
Cell Formulas
RangeFormula
F3:F5F3=OFFSET($C$3,(ROWS($C$3:C3)-1)*4,0)
G3:G5G3=INDEX($D$3:$D$13,MATCH(F3,$C$3:$C$13,0)+2)
Thank you for your help. Your formula works perfectly if the swift is always in the 3rd position after the first match and there is a consistent number of blank rows. Unfortunately my source file is a mess, with thousands of rows.
 
Upvote 0
I can offer a VBA solution if you're ok with that.
 
Upvote 0
Try this on a copy. It assume your data lay out is exactly like the pictures you provided.
VBA Code:
Sub FindSwift()
    Dim a, b
    Dim i As Long, j As Long
    Dim numRow As Long
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("Sheet2") 'change sheet name as needed
   
    numRow = ws.Cells(Rows.Count, "C").End(xlUp).Row '
    a = ws.Range("C3:D" & numRow).Value
    ReDim b(1 To numRow, 1 To 2)
    j = 1
 
    For i = 1 To numRow - 2
        If a(i, 1) <> "IBAN" And a(i, 1) <> "swift" And Not IsEmpty(a(i, 1)) Then
            b(j, 1) = a(i, 1)
            j = j + 1
        ElseIf a(i, 1) = "swift" Then
            b(j - 1, 2) = a(i, 2)
          
        End If
    Next i
    ws.Range("I3").Resize(j - 1, 2).Value = b
End Sub
 
Upvote 0
Try this on a copy. It assume your data lay out is exactly like the pictures you provided.
VBA Code:
Sub FindSwift()
    Dim a, b
    Dim i As Long, j As Long
    Dim numRow As Long
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Worksheets("Sheet2") 'change sheet name as needed
  
    numRow = ws.Cells(Rows.Count, "C").End(xlUp).Row '
    a = ws.Range("C3:D" & numRow).Value
    ReDim b(1 To numRow, 1 To 2)
    j = 1
 
    For i = 1 To numRow - 2
        If a(i, 1) <> "IBAN" And a(i, 1) <> "swift" And Not IsEmpty(a(i, 1)) Then
            b(j, 1) = a(i, 1)
            j = j + 1
        ElseIf a(i, 1) = "swift" Then
            b(j - 1, 2) = a(i, 2)
         
        End If
    Next i
    ws.Range("I3").Resize(j - 1, 2).Value = b
End Sub
Thank you so much, it's work wonderfully!!
 
Upvote 0
You're welcome. Cheers.
Hi Cubist,

Hope you don't mind me asking a little modification..
I'd like to get the same result as in column J (the swift code) but without the macro writing the other codes in column I, as those are hardcoded.

Thank you in advance.
 
Upvote 0

Forum statistics

Threads
1,215,327
Messages
6,124,280
Members
449,149
Latest member
mwdbActuary

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top