Typical matches; highlight and count them

Kishan

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

Hi,</SPAN></SPAN>

I want to find match of column C&D in the entire row and want to count the match</SPAN></SPAN>

Matches method example....</SPAN></SPAN>
Row 6 cells C6:D6 pattern "X1" look through in the column E:P in the row 6... following this method highlight each row column C:D patterns</SPAN></SPAN>

Note: once match find don't look back go for forward match only, example row 8 C8:D8 pattern "22" F8, G8, H8 has 2, 2, 2 in this case could be highlighted all 3, but as F8:G8 matched so look for H8:I8 if not match live it </SPAN></SPAN>

Below example show some matches</SPAN></SPAN>

Please need VBA help?</SPAN></SPAN>

Result data example</SPAN></SPAN>


Book1
ABCDEFGHIJKLMNOPQR
1
2
3
4
5P1P2P3P4P5P6P7P8P9P10P11P12P13P14Count Match
6X1212XX112X1123
71X2221XX22XX112
8221222XX22222X4
91X1221X11X12213
10X1X1X11X111XX15
11XXX1111X1X212X1
122X1112XXX111211
13X1XX1111111X113
141XX12121112X2X1
15X2X11X1111X11X1
16111111XXX1112X4
171212X112X2111X3
181XX112XX1X11X13
191XX11211221X112
20111X1111X111115
21X12X1112X112XX3
22111X1XX1X111113
2311111XX21111124
2411111111112XX15
2512211111111X111
2611X111111111215
27XXX111X112X1111
28X211211111XX1X1
291X221112XX111X2
3021XX11XX1X11111
311X12211112111X2
3211X122211X1X1X2
3321X1X1X11111111
34X11111212XX1XX2
351211X111X2X1XX1
36X1111X1211X1XX3
372X111XX11X11X11
381X2X1X1111121X3
39X1XX1X11X122113
401XX12X11X1X1213
411X11X1XX21111X4
42121111X1XX1X221
43X111111121221X1
442XX11X11XXXX1X1
45X211X1121111211
461XX1111111X11X3
47XX111XX21111XX3
48111X1X1111X1114
49XX11X1111111111
50111X1111211X115
5111111XX1X2XXXX2
52111121XXX111114
532X11X11XX111121
541XX111111212121
551111X11XXX11X14
56X111X121112X113
5711XX1X11XXX2113
58122111X21XXX1X1
5911X1121111X1X14
6012211X11111X1X1
61111121X1221X1X2
62211X111X11XX2X1
631111X11X1121125
64111111212111X14
651211222211112X3
66122111111XX11X1
671111X1XXX221212
6811XX11111112115
691X1X112111X1X13
70X111X11111X12X3
7111121X11X1111X4
7211X11X1111X1115
731XX2X1XX211X121
74XX1X1XX1XX11122
75
76
Sheet1


Thank you in advance</SPAN></SPAN>

Regards,</SPAN></SPAN>
Kishan</SPAN></SPAN>
 
Last edited:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG06Sep18
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, R [COLOR="Navy"]As[/COLOR] Variant, ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range("C6", Range("C" & Rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    R = Array(Dn.Value, Dn.Offset(, 1).Value)
        [COLOR="Navy"]For[/COLOR] ac = 2 To 14
            [COLOR="Navy"]If[/COLOR] Dn.Offset(, ac) = R(0) And Dn.Offset(, ac + 1) = R(1) [COLOR="Navy"]Then[/COLOR]
                c = c + 1: ac = ac + 1
            [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]Next[/COLOR] ac
        Dn.Offset(, 14) = c + 1: c = 0
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Try this:-
Code:
[COLOR=navy]Sub[/COLOR] MG06Sep18
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
Hi Mick, thank you for the quick response. The code counts are perfect, but does not highlights the matches in the rows, may I did not explained well I also need matches should be coloured in 2 different colours by alternating rows</SPAN></SPAN>

Please it could be possible
</SPAN></SPAN>

Thank you in advance
</SPAN></SPAN>

Regards,
</SPAN></SPAN>
Kishan
</SPAN></SPAN>
 
Upvote 0
Try this:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG06Sep24
[COLOR="Navy"]Dim[/COLOR] Rng [COLOR="Navy"]As[/COLOR] Range, Dn [COLOR="Navy"]As[/COLOR] Range, R [COLOR="Navy"]As[/COLOR] Variant, ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] col [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long[/COLOR]
[COLOR="Navy"]Set[/COLOR] Rng = Range("C6", Range("C" & Rows.Count).End(xlUp))
[COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Dn [COLOR="Navy"]In[/COLOR] Rng
    R = Array(Dn.Value, Dn.Offset(, 1).Value)
     col = IIf(col = vbGreen, vbYellow, vbGreen)
       Dn.Resize(, 2).Interior.Color = col
        [COLOR="Navy"]For[/COLOR] ac = 2 To 14
            [COLOR="Navy"]If[/COLOR] Dn.Offset(, ac) = R(0) And Dn.Offset(, ac + 1) = R(1) [COLOR="Navy"]Then[/COLOR]
               Dn.Offset(, ac).Resize(, 2).Interior.Color = col
                c = c + 1: ac = ac + 1
            [COLOR="Navy"]End[/COLOR] If
        [COLOR="Navy"]Next[/COLOR] ac
        Dn.Offset(, 14) = c + 1: c = 0
[COLOR="Navy"]Next[/COLOR] Dn
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Try this:-
Code:
[COLOR=navy]Sub[/COLOR] MG06Sep24
[COLOR=navy]Dim[/COLOR] Rng [COLOR=navy]As[/COLOR] Range, Dn [COLOR=navy]As[/COLOR] Range, R [COLOR=navy]As[/COLOR] Variant, ac [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] c [COLOR=navy]As[/COLOR] [COLOR=navy]Long,[/COLOR] col [COLOR=navy]As[/COLOR] [COLOR=navy]Long[/COLOR]
[COLOR=navy]Set[/COLOR] Rng = Range("C6", Range("C" & Rows.Count).End(xlUp))
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng
    R = Array(Dn.Value, Dn.Offset(, 1).Value)
     col = IIf(col = vbGreen, vbYellow, vbGreen)
       Dn.Resize(, 2).Interior.Color = col
        [COLOR=navy]For[/COLOR] ac = 2 To 14
            [COLOR=navy]If[/COLOR] Dn.Offset(, ac) = R(0) And Dn.Offset(, ac + 1) = R(1) [COLOR=navy]Then[/COLOR]
               Dn.Offset(, ac).Resize(, 2).Interior.Color = col
                c = c + 1: ac = ac + 1
            [COLOR=navy]End[/COLOR] If
        [COLOR=navy]Next[/COLOR] ac
        Dn.Offset(, 14) = c + 1: c = 0
[COLOR=navy]Next[/COLOR] Dn
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
Regards Mick
Mick, yes this is it!! Both colouring and count are perfect!!</SPAN></SPAN>

Thank you so much; I do appreciate your help and time and for solving it twice
</SPAN></SPAN>

Have a great day
</SPAN></SPAN>

Kind Regards,
</SPAN></SPAN>
Kishan :)
</SPAN></SPAN>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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