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
Try
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 1)
    j = 1
 
    For i = 1 To numRow - 2
        If a(i, 1) = "swift" Then
            b(j , 1) = a(i, 2)        
            j=j+1
        End If
    Next i
    ws.Range("J3").Resize(j - 1, 1).Value = b
End Sub
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Try
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 1)
    j = 1
 
    For i = 1 To numRow - 2
        If a(i, 1) = "swift" Then
            b(j , 1) = a(i, 2)      
            j=j+1
        End If
    Next i
    ws.Range("J3").Resize(j - 1, 1).Value = b
End Sub
Thank you. I see an issue now. My goal is to first match the code in column I with those in column C and then get the corresponding swift value in column D.
 
Upvote 0
Are you saying the values in I are not in order?
 
Upvote 0
Are you saying the values in I are not in order?
they could be in any order, and I need the swift only for the ones in the list, i.e. I could have only 3 of them and the result should be

ABC 123
GHI 555
EFG 648

Sorry
 
Upvote 0
Going back to the first code. You can change the location output. This can serve as your lookup table, then you can just do a VLOOKUP. Change "I3" to whereever you want it to output on the sheet.
VBA Code:
ws.Range("I3").Resize(j - 1, 2).Value = b
 
Upvote 0
Solution
Thank you for your help.
I eventually resorted to the formula route:
Excel Formula:
INDIRECT(ADDRESS(ROW(INDEX(C:C,MATCH(I3,C:C,0)))+ROW(INDEX(C:C,MATCH("swift",INDIRECT(ADDRESS(ROW(INDEX(C:C,MATCH(I3,C:C,0))),3,4)&":C100"),0)))-1,4,4))
 
Upvote 0

Forum statistics

Threads
1,215,193
Messages
6,123,566
Members
449,108
Latest member
rache47

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