Dynamically align column by matching substring

Statler

New Member
Joined
Jul 7, 2012
Messages
2
I'm trying to dynamic align column B to column A, but by matching a substring, and not by matching the whole content of the cell.

I have two column, with filenames in each (all with the same format, basically: Show.name.SxxExx.optional.title.source.codec-group.extention), but they might be a bit different, so i want to align them by matching the SxxExx in them which will always be the same.


I have this formula that returns the correct file name from B if it finds the same substring in A, in the same row, new column

=LOOKUP(9.99999999999999E+307,SEARCH(List2,A1),SINGLES)

'SINGLES' is the list in B column (file names to return if the exact 'SxxExx' substring extracted from it is found in column A.

'List2' is a column with a simple MID formula to extract the SxxExx number from column B file names (although i know it can be done by regex somehow and also have the correct regex, i just don't know what to do with it (it's "\.s[0-9][0-9]E[0-9][0-9]\." )


However this formula does not align them dynamicly in the same column they are already (column B).


I found this VB code (written by MickG here - thanks for that MickG!) that aligns by matching the whole string BUT will work only a cell in column B is EXACT as one in column A. what i need is to change it so it will align if only the SxxExx substring match (not case sensitive).

Code:
Sub MG17Sep38
Dim Rng1 As Range, Rng2 As Range, Dn As Range
Dim n As Long, RngAll, Ray
Set Rng1 = Range(Range("A1"), Range("A" & Rows.Count).End(xlUp))
    Set Rng2 = Range(Range("B1"), Range("B" & Rows.Count).End(xlUp))
        Set RngAll = Union(Rng1, Rng2)
             ReDim Ray(1 To Rows.Count, 1 To 2)
With CreateObject("scripting.dictionary")
.CompareMode = vbTextCompare
    For Each Dn In RngAll
        If Not .Exists(Dn.Value) Then
            n = n + 1
            .Add Dn.Value, n
                If Dn.Column = 1 Then
                    Ray(n, 1) = Dn.Value
                Else
                    Ray(n, 2) = Dn.Value
                End If
        Else
                If Dn.Column = 1 Then
                    Ray(.Item(Dn.Value), 1) = Dn.Value
                Else
                    Ray(.Item(Dn.Value), 2) = Dn.Value
                End If
        End If
    Next
RngAll.ClearContents
Range("A1").Resize(.Count, 2) = Ray
End With
End Sub

so i want to kind of merge, if you will, these two , into one vba code, and align B to A by matching the SxxExx substring. (xx can be any number, 2 digits)

I googled to death but i just don't have the knowledge to do it.

align by substring.xls
e5vptecnd


o and im using win-7, excel 2007, if it matters.
Hoping someone here can help
 
Last edited:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Can't seem to find the EDIT post button (on FF IE or Chrome) so here is the sheet:

Excel 2007
ABCDEFGH
1IF(NOT(ISERROR(SEARCH(".S??E??",B2,1))),MID(B2,SEARCH(".S??E??",B2,1)+1,6)," ")LOOKUP(9.99999999999999E+307,SEARCH(List2,A2),SINGLES)<<<the formula in the column below
2Nikita.S02E09.Fair.Trade.HDTV.XviD-ASAP.aviNikita.S02E10.HDTV.XviD-2HD.aviS02E10#N/A
3Nikita.S02E10.Guardians.HDTV.XviD-2HD.aviNikita.S02E11.HDTV.XviD-ASAP.aviS02E11Nikita.S02E10.HDTV.XviD-2HD.avi
4Nikita.S02E11.Pale.Fire.HDTV.XviD-ASAP.aviNikita.S02E16.HDTV.XviD-ASAP.aviS02E16Nikita.S02E11.HDTV.XviD-ASAP.avi
5Nikita.S02E12.Sanctuary.HDTV.XviD-ASAP.aviNikita.S02E21.HDTV.XviD-ASAP.aviS02E21#N/A
6Nikita.S02E13.Clean.Sweep.HDTV.XviD-LOL.avi #N/A
7Nikita.S02E14.Rogue.HDTV.XviD-LOL.avi #N/A
8Nikita.S02E15.Origins.HDTV.XviD-ASAP.avi #N/A
9Nikita.S02E16.Doublecross.HDTV.XviD-2HD.avi Nikita.S02E16.HDTV.XviD-ASAP.avi
10Nikita.S02E17.Arising.HDTV.XviD-FQM.avi #N/A
11Nikita.S02E18.Power.HDTV.XviD-2HD.avi #N/A

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
גיליון1

Worksheet Formulas
CellFormula
C2=IF(NOT(ISERROR(SEARCH(".S??E??",B2,1))),MID(B2,SEARCH(".S??E??",B2,1)+1,6)," ")
D2=LOOKUP(9.99999999999999E+307,SEARCH(List2,A2),SINGLES)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

Workbook Defined Names
NameRefers To
List2='C:\Users\cookie monster\Downloads\project\[Return single file name formula.xls]גיליון2'!$A$1:$A$10
SINGLES='C:\Users\cookie monster\Downloads\project\[Return single file name formula.xls]גיליון2'!$B$1:$B$4

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,215,443
Messages
6,124,887
Members
449,193
Latest member
ronnyf85

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