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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Can't seem to find the EDIT post button (on FF IE or Chrome) so here is the sheet:

Excel 2007
ABCDEFGH
IF(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
Nikita.S02E09.Fair.Trade.HDTV.XviD-ASAP.aviNikita.S02E10.HDTV.XviD-2HD.aviS02E10
Nikita.S02E10.Guardians.HDTV.XviD-2HD.aviNikita.S02E11.HDTV.XviD-ASAP.aviS02E11Nikita.S02E10.HDTV.XviD-2HD.avi
Nikita.S02E11.Pale.Fire.HDTV.XviD-ASAP.aviNikita.S02E16.HDTV.XviD-ASAP.aviS02E16Nikita.S02E11.HDTV.XviD-ASAP.avi
Nikita.S02E12.Sanctuary.HDTV.XviD-ASAP.aviNikita.S02E21.HDTV.XviD-ASAP.aviS02E21
Nikita.S02E13.Clean.Sweep.HDTV.XviD-LOL.avi
Nikita.S02E14.Rogue.HDTV.XviD-LOL.avi
Nikita.S02E15.Origins.HDTV.XviD-ASAP.avi
Nikita.S02E16.Doublecross.HDTV.XviD-2HD.avi Nikita.S02E16.HDTV.XviD-ASAP.avi
Nikita.S02E17.Arising.HDTV.XviD-FQM.avi
Nikita.S02E18.Power.HDTV.XviD-2HD.avi

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
[TD="align: center"]1[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]2[/TD]

[TD="align: right"]#N/A[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]3[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]4[/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]5[/TD]

[TD="align: right"]#N/A[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]6[/TD]

[TD="align: right"][/TD]

[TD="align: right"]#N/A[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]7[/TD]

[TD="align: right"][/TD]

[TD="align: right"]#N/A[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]8[/TD]

[TD="align: right"][/TD]

[TD="align: right"]#N/A[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]9[/TD]

[TD="align: right"][/TD]

[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]10[/TD]

[TD="align: right"][/TD]

[TD="align: right"]#N/A[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

[TD="align: center"]11[/TD]

[TD="align: right"][/TD]

[TD="align: right"]#N/A[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]

</tbody>
גיליון1

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Worksheet Formulas[TABLE="width: 100%"]
<thead>[TR="bgcolor: #E0E0F0"]
[TH="width: 10px"]Cell[/TH]
[TH="align: left"]Formula[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: #E0E0F0"]C2[/TH]
[TD="align: left"]=IF(NOT(ISERROR(SEARCH(".S??E??",B2,1))),MID(B2,SEARCH(".S??E??",B2,1)+1,6)," ")[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: #E0E0F0"]D2[/TH]
[TD="align: left"]=LOOKUP(9.99999999999999E+307,SEARCH(List2,A2),SINGLES)[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]

[TABLE="width: 85%"]
<tbody>[TR]
[TD]Workbook Defined Names[TABLE="width: 100%"]
<thead>[TR="bgcolor: #E0E0F0"]
[TH="width: 10px"]Name[/TH]
[TH="align: left"]Refers To[/TH]
[/TR]
</thead><tbody>[TR]
[TH="width: 10px, bgcolor: #E0E0F0"]List2[/TH]
[TD="align: left"]='C:\Users\cookie monster\Downloads\project\[Return single file name formula.xls]גיליון2'!$A$1:$A$10[/TD]
[/TR]
[TR]
[TH="width: 10px, bgcolor: #E0E0F0"]SINGLES[/TH]
[TD="align: left"]='C:\Users\cookie monster\Downloads\project\[Return single file name formula.xls]גיליון2'!$B$1:$B$4[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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