The code below from MickG, is working perfect if the headers are placed in Range (P1:AD1) with the lay out below.</SPAN></SPAN>
But now I need to change the layout as shown below. For that I need help that code to be modified to work with the layout below. I tried a lot but could not get it work</SPAN></SPAN>
Please help </SPAN></SPAN>
Regards,</SPAN></SPAN>
Kishan</SPAN></SPAN>
Code:
[COLOR=#000080]Sub[/COLOR] MG22Oct22
[COLOR=navy]Dim[/COLOR] Rng [COLOR=navy]As[/COLOR] Range
[COLOR=navy]Dim[/COLOR] Dn [COLOR=navy]As[/COLOR] Range
[COLOR=navy]Dim[/COLOR] Ac [COLOR=navy]As[/COLOR] [COLOR=navy]Integer[/COLOR]
[COLOR=navy]Dim[/COLOR] n [COLOR=navy]As[/COLOR] [COLOR=navy]Integer[/COLOR]
[COLOR=navy]Dim[/COLOR] Temp [COLOR=navy]As[/COLOR] [COLOR=navy]String[/COLOR]
[COLOR=navy]Dim[/COLOR] R [COLOR=navy]As[/COLOR] [COLOR=navy]Integer[/COLOR]
[COLOR=navy]Dim[/COLOR] p [COLOR=navy]As[/COLOR] [COLOR=navy]Integer[/COLOR]
[COLOR=navy]Set[/COLOR] Rng = Range(Range("A2"), Range("A" & Rows.Count).End(xlUp))
Rng.Offset(, 15).Resize(, 15).ClearContents
[COLOR=navy]For[/COLOR] [COLOR=navy]Each[/COLOR] Dn [COLOR=navy]In[/COLOR] Rng
ReDim ray(1 To 14, 1 To 2)
Temp = Dn
n = 1
[COLOR=navy]For[/COLOR] Ac = 1 To 14
[COLOR=navy]If[/COLOR] Not Dn(, Ac) = Temp [COLOR=navy]Then[/COLOR]
n = n + 1
Temp = Dn(, Ac)
[COLOR=navy]End[/COLOR] If
ray(n, 1) = Dn(, Ac): ray(n, 2) = ray(n, 2) + 1
[COLOR=navy]Next[/COLOR] Ac
p = 1
[COLOR=navy]For[/COLOR] Ac = 1 To n
[COLOR=navy]For[/COLOR] R = p To 15
[COLOR=navy]If[/COLOR] Not ray(Ac, 1) = Cells(1, R + 15) [COLOR=navy]Then[/COLOR]
[COLOR=navy]Else[/COLOR]
Cells(Dn.Row, R + 15) = ray(Ac, 2)
p = R
[COLOR=navy]Exit[/COLOR] For
[COLOR=navy]End[/COLOR] If
[COLOR=navy]Next[/COLOR] R
[COLOR=navy]Next[/COLOR] Ac
[COLOR=navy]Next[/COLOR] Dn
Book1 | |||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | AA | AB | AC | AD | AE | |||
1 | P1 | P2 | P3 | P4 | P5 | P6 | P7 | P8 | P9 | P10 | P11 | P12 | P13 | P14 | 1 | X | 2 | 1 | X | 2 | 1 | X | 2 | 1 | X | 2 | 1 | X | 2 | ||||
2 | 1 | X | 2 | 1 | X | 2 | 1 | X | 2 | 1 | X | 2 | 1 | X | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |||||
3 | 1 | 1 | 1 | X | X | 2 | 2 | X | 1 | 1 | 1 | 1 | 1 | X | 3 | 2 | 2 | 1 | 5 | 1 | |||||||||||||
4 | 2 | 2 | X | X | 1 | 1 | X | 2 | 1 | 1 | X | X | X | 2 | 2 | 2 | 2 | 1 | 1 | 2 | 3 | 1 | |||||||||||
5 | 1 | X | X | X | X | 1 | 1 | 1 | 1 | X | X | 2 | 2 | X | 1 | 4 | 4 | 2 | 2 | 1 | |||||||||||||
6 | X | 1 | 2 | 2 | X | X | 2 | 2 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 2 | 2 | 6 | |||||||||||||
7 | 2 | 2 | 2 | 1 | 2 | 2 | 2 | 2 | 2 | X | X | X | X | X | 3 | 1 | 5 | 5 | |||||||||||||||
8 | 1 | X | X | 2 | 2 | X | X | 2 | 2 | X | X | 2 | 2 | X | 1 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | |||||||||||
9 | 1 | X | 2 | X | 2 | 1 | X | 2 | 1 | X | 2 | 1 | X | 2 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |||||
10 | 1 | X | X | X | 1 | 1 | 1 | 1 | 1 | X | X | 2 | 1 | 2 | 1 | 3 | 5 | 2 | 2 | 1 | |||||||||||||
11 | 1 | X | 2 | 1 | X | 2 | 1 | X | 2 | 1 | X | 2 | 1 | 2 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |||||
12 | |||||||||||||||||||||||||||||||||
13 | |||||||||||||||||||||||||||||||||
Sheet1 |
But now I need to change the layout as shown below. For that I need help that code to be modified to work with the layout below. I tried a lot but could not get it work</SPAN></SPAN>
Book1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | AA | AB | AC | AD | AE | AF | AG | AH | AI | AJ | AK | AL | AM | AN | AO | AP | AQ | AR | AS | AT | AU | AV | AW | AX | AY | AZ | |||
1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
5 | P1 | P2 | P3 | P4 | P5 | P6 | P7 | P8 | P9 | P10 | P11 | P12 | P13 | P14 | 1 | X | 2 | 1 | X | 2 | 1 | X | 2 | 1 | X | 2 | 1 | X | 2 | |||||||||||||||||||||||||
6 | 1 | X | 2 | 1 | X | 2 | 1 | X | 2 | 1 | X | 2 | 1 | X | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | ||||||||||||||||||||||||||
7 | 1 | 1 | 1 | X | X | 2 | 2 | X | 1 | 1 | 1 | 1 | 1 | X | 3 | 2 | 2 | 1 | 5 | 1 | ||||||||||||||||||||||||||||||||||
8 | 2 | 2 | X | X | 1 | 1 | X | 2 | 1 | 1 | X | X | X | 2 | 2 | 2 | 2 | 1 | 1 | 2 | 3 | 1 | ||||||||||||||||||||||||||||||||
9 | 1 | X | X | X | X | 1 | 1 | 1 | 1 | X | X | 2 | 2 | X | 1 | 4 | 4 | 2 | 2 | 1 | ||||||||||||||||||||||||||||||||||
10 | X | 1 | 2 | 2 | X | X | 2 | 2 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 2 | 2 | 2 | 6 | ||||||||||||||||||||||||||||||||||
11 | 2 | 2 | 2 | 1 | 2 | 2 | 2 | 2 | 2 | X | X | X | X | X | 3 | 1 | 5 | 5 | ||||||||||||||||||||||||||||||||||||
12 | 1 | X | X | 2 | 2 | X | X | 2 | 2 | X | X | 2 | 2 | X | 1 | 2 | 2 | 2 | 2 | 2 | 2 | 1 | ||||||||||||||||||||||||||||||||
13 | 1 | X | 2 | X | 2 | 1 | X | 2 | 1 | X | 2 | 1 | X | 2 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | ||||||||||||||||||||||||||
14 | 1 | X | X | X | 1 | 1 | 1 | 1 | 1 | X | X | 2 | 1 | 2 | 1 | 3 | 5 | 2 | 2 | 1 | ||||||||||||||||||||||||||||||||||
15 | 1 | X | 2 | 1 | X | 2 | 1 | X | 2 | 1 | X | 2 | 1 | 2 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | ||||||||||||||||||||||||||
16 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
Sheet2 |
Please help </SPAN></SPAN>
Regards,</SPAN></SPAN>
Kishan</SPAN></SPAN>
Last edited: