In the formula instead of putting column reference can be used column numbers.

Kishan

Well-known Member
Joined
Mar 15, 2011
Messages
1,648
Office Version
  1. 2010
Platform
  1. Windows
Using Excel 2000

Hi,

In the columns C:H there are results which columns numbers are (3-4-5-6-7-8)

In the column O5:Y5 I have header with 4 unique Pattern

In the range O6:Y10 there is formula SUMPRODUCT that is populating result of header O5:Y5 header unique patterns of different "4 columns" for that i need to change formula for the column I want to be checked.

I need help is it possible that formulas are in the O6:Y10 can pick the column reference from the
Columns J:M in that way i do not need to change the formula just changing the numbers in the range J6:M10 I will get results.

Here below is a list of formula are used for the results.

VBA Code:
O6:Y6 =SUMPRODUCT(--($C$6:$C$5006&" | " &$D$6:$D$5006&" - "&$E$6:$E$5006&" | "&$F$6:$F$5006=O$5))
O7:Y7 =SUMPRODUCT(--($C$6:$C$5006&" | " &$D$6:$D$5006&" - "&$E$6:$E$5006&" | "&$G$6:$G$5006=O$5))
O8:Y8 =SUMPRODUCT(--($C$6:$C$5006&" | " &$D$6:$D$5006&" - "&$E$6:$E$5006&" | "&$H$6:$H$5006=O$5))
O9:Y9 =SUMPRODUCT(--($D$6:$D$5006&" | " &$E$6:$E$5006&" - "&$F$6:$F$5006&" | "&$G$6:$G$5006=O$5))
O10:Y10 =SUMPRODUCT(--($D$6:$D$5006&" | " &$E$6:$E$5006&" - "&$G$6:$G$5006&" | "&$H$6:$H$5006=O$5))

If I am not asking much does it is possible VBA solution that would be great assist

*ABCDEFGHIJKLMNOPQRSTUVWXYZAA
1
2
3
4ColColColColColColColumn nºColumn nºColumn nºColumn nº4 Patt4 Patt4 Patt4 Patt4 Patt4 Patt4 Patt4 Patt4 Patt4 Patt4 Patt
5345678Column nºColumn nºColumn nºColumn nº1 | 1 - 1 | 11 | 1 - 1 | X1 | 1 - X | X1 | X - 1 | 11 | X - 1 | 2X | 1 - X | XX | 1 - 2 | 2X | X - 2 | 2X | 2 - X | X2 | 1 - 2 | X2 | X - 1 | 2
611112134566604030110144
7212XXX345753010202032
8XX2221345883020104041
92X1221456730300020000
10X1XX11457831110200000
112X122X
12212X11
13212X1X
14111XXX
15212X11
16XX2212
17111121
182X121X
19X1XXX1
20212X21
21212X21
22XX221X
23XX2212
24111111
25212XX1
26XX2212
271X11XX
28XX2212
29212X21
30111111
31XX2211
32111X21
331X11X1
34XX2211
35212X2X
36212X11
37111X11
38X1XXXX
39212X21
40111XX1
41212X1X
42111XX1
43212XX1
44XX2211
45111X12
462X12X2
471X1111
48XX2221
49212X21
5011111X
51XX221X
521X11XX
5311112X
54
55

Result image is attached

Thank you in advance

Regards,
Kishan
 

Attachments

  • Column Num In Formula.png
    Column Num In Formula.png
    60.7 KB · Views: 3

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Maybe...

O6
=SUMPRODUCT(--(INDEX($C$6:$H$5006,0,MATCH($J6,$C$5:$H$5,0))&" | " &INDEX($C$6:$H$5006,0,MATCH($K6,$C$5:$H$5,0))&" - "&INDEX($C$6:$H$5006,0,MATCH($L6,$C$5:$H$5,0))&" | "&INDEX($C$6:$H$5006,0,MATCH($M6,$C$5:$H$5,0))=O$5))
copy across and down

Hope this helps

It would be easier if in J:M there was the relative position of the columns, that is, for example in
J6:M6
1 2 3 4
in J7:M7
1 2 3 5
etc

M.
 
Upvote 0
Maybe...

O6
=SUMPRODUCT(--(INDEX($C$6:$H$5006,0,MATCH($J6,$C$5:$H$5,0))&" | " &INDEX($C$6:$H$5006,0,MATCH($K6,$C$5:$H$5,0))&" - "&INDEX($C$6:$H$5006,0,MATCH($L6,$C$5:$H$5,0))&" | "&INDEX($C$6:$H$5006,0,MATCH($M6,$C$5:$H$5,0))=O$5))
copy across and down

Hope this helps

It would be easier if in J:M there was the relative position of the columns, that is, for example in
J6:M6
1 2 3 4
in J7:M7
1 2 3 5
etc

M.
Marcelo Branco, your given formula worked as request, it was not problem I changed as per you suggestion column numbers it is easier for me too indeed. Here below is attached a new changed layout.

I have 14 columns and 81 patterns across and 1001 rows to fill down total 81081 cells to fill the formula so it is going to be a very slow procedure might it crash and excel does not response my request is there and VBA solution that can result in values only.

Please help if it could be done. As per present layout and than I will extend the ranges and will adjust it as per my need.

Thank you very much for your kind help.

*ABCDEFGHIJKLMNOPQRSTUVWXYZAA
1
2
3
4ColColColColColColColumn nºColumn nºColumn nºColumn nº4 Patt4 Patt4 Patt4 Patt4 Patt4 Patt4 Patt4 Patt4 Patt4 Patt4 Patt
5123456Column nºColumn nºColumn nºColumn nº1 | 1 - 1 | 11 | 1 - 1 | X1 | 1 - X | X1 | X - 1 | 11 | X - 1 | 2X | 1 - X | XX | 1 - 2 | 2X | X - 2 | 2X | 2 - X | X2 | 1 - 2 | X2 | X - 1 | 2
611112112346604030110144
7212XXX123553010202032
8XX2221123683020104041
92X1221234530300020000
10X1XX11235631110200000
112X122X
12212X11
13212X1X
14111XXX
15212X11
16XX2212
17111121
182X121X
19X1XXX1
20212X21
21212X21
22XX221X
23XX2212
24111111
25212XX1
26XX2212
271X11XX
28XX2212
29212X21
30111111
31XX2211
32111X21
331X11X1
34XX2211
35212X2X
36212X11
37111X11
38X1XXXX
39212X21
40111XX1
41212X1X
42111XX1
43212XX1
44XX2211
45111X12
462X12X2
471X1111
48XX2221
49212X21
5011111X
51XX221X
521X11XX
5311112X
54
55

Regards,
Kishan
 

Attachments

  • Column Num In Formula1.png
    Column Num In Formula1.png
    60.6 KB · Views: 6
Upvote 0
See if the macro below does what you're looking for - it worked for me using the data sample in post #3
(relative positions in J:M)

VBA Code:
Sub aTest()
    Dim lNumRowsInd As Long, arrIndex(1 To 4) As Variant, arrStrs(1 To 11) As Variant
    Dim i As Long, j As Long, k As Long, n As Long, lRow As Long
    Dim spl As Variant, lCounter As Long
    
    'Initialize variables
    Dim vIndex As Variant
    vIndex = Range("J6:M" & Cells(Rows.Count, "J").End(xlUp).Row)
    Dim vStrings As Variant
    vStrings = Range("O5:Y5").Value
    For i = 1 To 11
        arrStrs(i) = Replace(Replace(vStrings(1, i), "-", "|"), " ", "")
    Next i
    lNumRowsInd = Cells(Rows.Count, "J").End(xlUp).Row
    Dim vResult As Variant
    vResult = Range("O6:Y" & lNumRowsInd).Value
    Dim vData As Variant
    vData = Range("C6:H" & Cells(Rows.Count, "C").End(xlUp).Row)
    
    'Loop
    For i = 1 To UBound(vResult, 1)
        For j = 1 To 4
            arrIndex(j) = vIndex(i, j)
        Next j
        For k = 1 To UBound(vResult, 2)
            spl = Split(arrStrs(k), "|")
            vResult(i, k) = 0
            For lRow = 1 To UBound(vData, 1)
                lCounter = 0
                For n = 1 To 4
                    If CStr(vData(lRow, arrIndex(n))) = CStr(spl(n - 1)) Then _
                        lCounter = lCounter + 1
                Next n
                If lCounter = 4 Then vResult(i, k) = vResult(i, k) + 1
            Next lRow
        Next k
    Next i
    'Transfer results
    Range("O6:Y" & lNumRowsInd) = vResult
End Sub

Hope this helps

M.
 
Upvote 0
Solution
See if the macro below does what you're looking for - it worked for me using the data sample in post #3
(relative positions in J:M)

VBA Code:
Sub aTest()
    Dim lNumRowsInd As Long, arrIndex(1 To 4) As Variant, arrStrs(1 To 11) As Variant
    Dim i As Long, j As Long, k As Long, n As Long, lRow As Long
    Dim spl As Variant, lCounter As Long
   
    'Initialize variables
    Dim vIndex As Variant
    vIndex = Range("J6:M" & Cells(Rows.Count, "J").End(xlUp).Row)
    Dim vStrings As Variant
    vStrings = Range("O5:Y5").Value
    For i = 1 To 11
        arrStrs(i) = Replace(Replace(vStrings(1, i), "-", "|"), " ", "")
    Next i
    lNumRowsInd = Cells(Rows.Count, "J").End(xlUp).Row
    Dim vResult As Variant
    vResult = Range("O6:Y" & lNumRowsInd).Value
    Dim vData As Variant
    vData = Range("C6:H" & Cells(Rows.Count, "C").End(xlUp).Row)
   
    'Loop
    For i = 1 To UBound(vResult, 1)
        For j = 1 To 4
            arrIndex(j) = vIndex(i, j)
        Next j
        For k = 1 To UBound(vResult, 2)
            spl = Split(arrStrs(k), "|")
            vResult(i, k) = 0
            For lRow = 1 To UBound(vData, 1)
                lCounter = 0
                For n = 1 To 4
                    If CStr(vData(lRow, arrIndex(n))) = CStr(spl(n - 1)) Then _
                        lCounter = lCounter + 1
                Next n
                If lCounter = 4 Then vResult(i, k) = vResult(i, k) + 1
            Next lRow
        Next k
    Next i
    'Transfer results
    Range("O6:Y" & lNumRowsInd) = vResult
End Sub

Hope this helps

M.
Marcelo Branco, I am very gratefully to you for taking a time from your busy schedule and giving a macro solution for me as per my need. The code worked fine and it took 0.00:01 second as per using the data sample post #3.

Modified a code to work with my full data using in 14 columns, 81 patterns and 1001 rows populating a results across 1001*81 = 81081 cells it took only 00:05:38 minutes. The code you build it is so easy to understand and very simple to modify it is unbelievable and amazing! ?

I am very obliged to you for giving me a huge and great timesaver solution.

I wish for you to have a great weekend and Good Luck.

Kind Regards
Kishan :)
 
Upvote 0
Great, the code has worked for you. Glad to help.

Just for curiosity. How long did it take for your real case?
I didn't quite understand what 00:05:38 minutes means (?)

M.
 
Upvote 0
Great, the code has worked for you. Glad to help.

M.
Marcelo Branco, I am grateful to you for that the code worked with my older version perfect and smoothly. ?

Just for curiosity. How long did it take for your real case?
I didn't quite understand what 00:05:38 minutes means (?)

M.
As per sample post #3 that has 6 columns with 48 row data, columns to check 5 rows and header Patt 11 to populate 11*5 = 55 cells to populate which took time 01 second.

After modifying real data extending it to 6 to 14 columns with 48 to 2300+ rows + columns to check 5 rows to 1001 and + extending header 11 to 81 that mean 1001*81 = 81081 cells to populate with comprehensive data code took only time to finish 5 minutes and 38 seconds Without any problem at all. I am very happy with your code solution. :)

Good Luck to you and have a pleasant time.

Kind Regards
Kishan
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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