Join and Index Data

pwill

Active Member
Joined
Nov 22, 2015
Messages
406
Hi can anyone help with the following code?

On Sheet2 I have the following
MyLetters in "E4:K4"
MyNumbers in "D5:D30"
<strike></strike>
MyData in "E5:K30"
MyResults in "AN20:AT26"<strike></strike>

The code works fine but I want to change the results so that instead of Indexing every row with (MyLetters) within (MyData) into the Results, I want to index the Rows that only have 2 or more of (MyLetters) into the Results. In the example below (ResultsA) shows the results using every Row and (MyLetters) and ResultsB shows what the results would be if only indexing Rows with 2 or more MyLetters.(To get ResultsB I cleared all the Letters on rows(5,8,11,13,14,16,22,24,25,28 and ran the code again)

Could I add something like 'COUNTIF(Row, MyData) >= 2' to the code somewhere to achieve this?

Code:
[FONT=Verdana]
Sub IndexMyData()
[/FONT]
[FONT=Verdana]    Dim MyRow(26), InSht As Worksheet, OutSht As Worksheet
    Dim c As Integer
    Dim i As Long
    Dim j As Long
    Dim r As Long
    Dim MyResults
    Dim CustOrd
    Dim MyData
    Dim MyNums
    Dim MyLtrs
    
        Application.EnableEvents = False
    
        Set InSht = Sheet2
        Set OutSht = Sheet2
        Set MyResults = OutSht.Range("AN20:AT26")
    
        MyData = InSht.Range("E5:K30")
        MyNums = InSht.Range("D5:D30")
        MyLtrs = InSht.Range("E4:K4")
    
            For i = 1 To 26
                MyRow(i) = " " & Join(WorksheetFunction.Index(MyData, i, 0)) & " "
                CustOrd = CustOrd & MyNums(i, 1) & ","
            Next i
    
            MyResults.ClearContents
            For i = 1 To 7
            c = 0
        
            For j = 1 To 26
                If InStr(MyRow(j), " " & MyLtrs(1, i) & " ") > 0 Then
                    c = c + 1
                        MyResults.Cells(c, i) = MyNums(j, 1)
                        If c = 7 Then Exit For
                    End If
                Next j
            Next i
    
            With OutSht.Sort
                .SortFields.Clear
                    For i = 1 To 7
                        .SortFields.Add Key:=MyResults.Cells(i, 1), CustomOrder:=CVar(CustOrd)
                    Next i
                .SetRange MyResults
                .Orientation = xlLeftToRight
                .Apply
            End With
    
            Application.EnableEvents = True
    
End Sub[/FONT]

ABCDEFGHI
1
2
3
4MyLtrsABCDEFGResults A
517121721D4043ANAOAPAQARASATAU
62510A19C384120122491113
738131822304144211771311121719
84491418B3740222010211918
959141923314245232517242625
106381317253639242626
11710A202432434625
12827121624353826
13911162125E4447
14101611A233437Results B
1511121722B3445FANAOAPAQARASATAU
161205101422E3620221111131725
1713131823C3546G21131717191925
1814-1491321323522262626
19151419242836475023
2016-2381220313424
2117A2025D37F5125
2218-327111930E26
23191621B3038G52
2420-4161018D32
25211722C31395053
2622-5059172831
272318232832405154
2824-6-14816C30
29251924DE415255
3026-7-237ABD

<tbody>
</tbody>
<strike>
</strike>

Any help would be appreciated

Regards

pwill
 
Last edited:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Sorry, got the Sheet Columns wrong here


ABCDEFGHI
1
2
3
4MyLtrsABCDEFG

<tbody>
</tbody>

They should be and "E4:K4" are MyLetters

DEFGHIJKL
1
2
3
4MyLtrsABCDEFG

<tbody>
</tbody>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,734
Members
448,987
Latest member
marion_davis

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