Taking occurrences of unique numbers (two tables) and placing results list across rows with corresponding occurrence values [Compare Two Tables, look

ProgramUser

Board Regular
Joined
Apr 15, 2014
Messages
75
Dear Excellers,

This is part of a larger project involving trigonometric ratios.

The Situation;
I have two tables, one table (A22:E22) with unique numbers derived from trigonometric functions, I then check this table’ values for duplicates using a vba code snippet I wrote (see below) into a corresponding table at (G3:K22), note: first line at row G2:K2 (from A2:E2) does not show results deliberately.

Table 1.

Excel 2012
ABCDEFGHIJK
1TRIG1TRIG2TRIG3TRIG4TRIG5OCC1OCC2OCC3OCC4OCC5
21360919421263271726526265
3262651808224118183002193000000
4273871486614211284652807500000
5180822998814047124642420210000
6155072527825354231891700400000
7212872980528016278301393900000
8122802163117004156551905100100
9150062245224651160582140700000
10255491731529968284851945800000
11277722346414652207501639200000
12243521637823869220781430600000
13189272819526059295421948400000
14175872551819917193702860500000
15229511681319239208861301100000
16204521495126168192731652200000
17297942346822374212871903300090
18265752413924857250491791400000
19275881342017720167882592800000
201308220248194212455823934001700
21183432773712536282172133300000
22280151670516473171682208600000
Test of Index Lookup


.....I need to then copy or rather populate the quantity of duplicate records (as evidenced from G3:K22) into another row (say…transposed across rows) with the TRIG Functions at top with the corresponding occurrence value below it, like this;

Table 2 (sample).

Excel 2012
GHIJKLMNOPQRSTU
1OCC1OCC2OCC3OCC4OCC5
2
300000
400000
510000
600000
700000
800100
900000
1000000
1100000136092646227387120591550721287122801500625549
1200000NotMatchNotMatch#N/ANotMatchNotMatchNotMatchNotMatchNotMatchNotMatch
1300000
1400000
1500000
1600000
1700090
1800000
1900000
20001700
2100000
2200000
Test of Index Lookup
Cell Formulas
RangeFormula
M12{=IF($G3=0,"NotMatch",(INDEX($G$3:$K$22,MATCH($A2,$A$2:$E$22,0)*ROW($A2),ROW($A2))))}
N12{=IF($G4=0,"NotMatch",(INDEX($G$3:$K$22,MATCH($A2,$A$2:$E$22,0)*ROW($A2),ROW($A2))))}
O12{=IF($G5=0,"NotMatch",(INDEX($G$3:$K$22,MATCH($A2,$A$2:$E$22,0)*ROW($A2),ROW($A2))))}
P12{=IF($G6=0,"NotMatch",(INDEX($G$3:$K$22,MATCH($A2,$A$2:$E$22,0)*ROW($A2),ROW($A2))))}
Q12{=IF($G7=0,"NotMatch",(INDEX($G$3:$K$22,MATCH($A2,$A$2:$E$22,0)*ROW($A2),ROW($A2))))}
R12{=IF($G8=0,"NotMatch",(INDEX($G$3:$K$22,MATCH($A2,$A$2:$E$22,0)*ROW($A2),ROW($A2))))}
S12{=IF($G9=0,"NotMatch",(INDEX($G$3:$K$22,MATCH($A2,$A$2:$E$22,0)*ROW($A2),ROW($A2))))}
T12{=IF($G10=0,"NotMatch",(INDEX($G$3:$K$22,MATCH($A2,$A$2:$E$22,0)*ROW($A2),ROW($A2))))}
U12{=IF($G11=0,"NotMatch",(INDEX($G$3:$K$22,MATCH($A2,$A$2:$E$22,0)*ROW($A2),ROW($A2))))}
Press CTRL+SHIFT+ENTER to enter array formulas.


....Note that matches do occur at G5, and I8, and I20, and J17….therefore;
I could just populate say 20 columns across with the TRIG Numbers, which would then mean that I would need multiple rows dependent on the amount of TRIG functions I am testing…..like this;

Table 3.

Excel 2012
IJKLMNOPQRS
1OCC3OCC4OCC5
2
3000
4000
5000
6000
7000
8100
9000
10000
1100013609264622738712059155072128712280
12000NotMatchNotMatch#N/ANotMatchNotMatchNotMatchNotMatch
1300019421180821486629988252782980521631
14000ResultResultResult...
1500026327241181421114047253542801617004
16000ResultResultResult...
17090
18000
19000
201700
21000
22000
Test of Index Lookup
Cell Formulas
RangeFormula
M12{=IF($G3=0,"NotMatch",(INDEX($G$3:$K$22,MATCH($A2,$A$2:$E$22,0)*ROW($A2),ROW($A2))))}
N12{=IF($G4=0,"NotMatch",(INDEX($G$3:$K$22,MATCH($A2,$A$2:$E$22,0)*ROW($A2),ROW($A2))))}
O12{=IF($G5=0,"NotMatch",(INDEX($G$3:$K$22,MATCH($A2,$A$2:$E$22,0)*ROW($A2),ROW($A2))))}
P12{=IF($G6=0,"NotMatch",(INDEX($G$3:$K$22,MATCH($A2,$A$2:$E$22,0)*ROW($A2),ROW($A2))))}
Q12{=IF($G7=0,"NotMatch",(INDEX($G$3:$K$22,MATCH($A2,$A$2:$E$22,0)*ROW($A2),ROW($A2))))}
R12{=IF($G8=0,"NotMatch",(INDEX($G$3:$K$22,MATCH($A2,$A$2:$E$22,0)*ROW($A2),ROW($A2))))}
S12{=IF($G9=0,"NotMatch",(INDEX($G$3:$K$22,MATCH($A2,$A$2:$E$22,0)*ROW($A2),ROW($A2))))}
Press CTRL+SHIFT+ENTER to enter array formulas.


VBA Code for checking occurences;

Code:
' /////////////
' Trig Digits////
' /////////////
' Code by ProgramUser Jan 2016


Public Sub Count_Match5_TickTape1a()
    Dim myRange As Range
    Dim c As Range
    
    ' ######
    'Speed up code execution
    ' ######
    'Get current state of various Excel settings;


    screenUpdateState = Application.ScreenUpdating
    statusBarState = Application.DisplayStatusBar
    calcState = Application.Calculation
    eventsState = Application.EnableEvents
    displayPageBreakState = ActiveSheet.DisplayPageBreaks 'sheet-level setting only


    'Switch off Excel functionality so code runs faster
    Application.ScreenUpdating = False
    Application.DisplayStatusBar = False
    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False
    ActiveSheet.DisplayPageBreaks = False 'sheet-level setting only
    
    '  ####
    '  Basic Looping starts
    '  ####
    Set myRange = Range("A2", Range("E1048576").End(xlUp))
    
    For Each c In myRange
        For i = c.Row - 2 To 1 Step -1
            If Not IsError(Application.Match(c, myRange.Rows(i), 0)) Then
            ' so I can remember stuff
            ' Syntax for .Offset = (example) Range.Offset(RowOffset, ColumnOffset)
            ' Omitting the first number in the Offset reference below, i.e. (2,5) ""(,5)"" means we are only concerned with the column and not the row
                c.Offset(, 6) = c.Row - 2 - i
                Exit For
            Else
                c.Offset(, 6) = 0
            End If
        Next i
    Next c
        'after my code completes, restore previous state;


    Application.ScreenUpdating = screenUpdateState
    Application.DisplayStatusBar = statusBarState
    Application.Calculation = calcState
    Application.EnableEvents = eventsState
    ActiveSheet.DisplayPageBreaks = displayPageBreaksState 'sheet-level setting only
End Sub

My Problem
I have tried various iterations of INDEX/MATCH using ROW to show these matches but without any luck. Additionally, I could just use copy/paste function from within VBA, I don’t mind. Does anyone have any suggestions? A VBA option would be nice….

Regards,
ProgramUser
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hey everyone,

Sorry, I forgot to clarify, my VBA code above works just fine however, it is just the correct placement of the occurrences that I am after in column M through to column AF as per above examples.

Cheers, and looking forward to any advice you may have.

Regards,

ProgramUser
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,693
Members
449,117
Latest member
Aaagu

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