Search for topics based on their groups.

harzer

Board Regular
Joined
Dec 15, 2021
Messages
153
Office Version
  1. 2016
Platform
  1. Windows
Hello everyone,
I submit to you my problem that I do not know how to go about solving it, I will explain to you and I will give you the details to resolve it:
In my "Growth" sheet, I have 16 groups of 3 lines, each group has the group number which is in column "A", in my example (here) each group has 3 lines, it can happen that the group has 4 lines.
For greater visibility of the various groups, I colored each group a different color.
The work that I am asking you to do (in vba please) consists of finding in which group all the subjects in column "F" are located.
To better explain the approach to implement, we will take an example, this is the first subject found in cell “F2”: AE27-022/2022 M
We will look for the groups where the value of cell "F2" (AE27-022/2022 M) is located, to begin with, it is found in cell "F2" which is located in group 1, if continue to search for this value in column "F", we also find it in cell "F20" which is in group 7, and we find it in cell "F30" which is in group 10.
In summary, the value of cell "F2" is found in the groups: 1 - 7 - 10, we can then mark the numbers of the groups separated by a hyphen (-) in cell "J2" = 1 - 7 - 10
2nd example, we will look for the groups of the subject which is located in cell "F3" = (5919-001/2023 M), the groups for this subject are: 1 - 11 - 13, we can then mark the numbers of the groups separated by a hyphen (-) in cell "J3" = 1 - 11 – 13
We recommend doing the same for all subjects in column "F" and marking the groups in column "J" on the same line of the subject sought.
Unless I'm mistaken, I have put the results for all subjects in column "J".
I hope I was clear enough in my explanations, otherwise, I remain at your disposal for other additional information.
Thank you for your propositions.

Classeur1
ABCDEFGHIJ
1GroupesFemellePèreMère13MâlePèreMèreGroupes
21MN96-010/2021 FMN96-002/2020 MMN96-020/2020 FAE27-022/2022 MAE27-049/2021 MAE27-003/2021 F1 - 7 - 10
35919-001/2023 M3024-058/2020 M3024-011/2022 F1 - 11 - 13
4
52MN96-034/2021 FMN96-050/2020 MMN96-013/2019 FAE27-035/2022 MMN96-005/2021 MAE27-068/2021 F2 - 8
6AE27-069/2023 MAE27-018/2022 MMN96-045/2022 F2 - 3 - 4 - 8
7MN96-008/2021 MMN96-002/2020 MMN96-020/2020 F2 - 3 - 4 - 5 - 6 - 16
83AE27-026/2022 FMN96-046/2019 MMN96-036/2021 FAE27-069/2023 MAE27-018/2022 MMN96-045/2022 F3 - 4 - 8 - 2
9MN96-008/2021 MMN96-002/2020 MMN96-020/2020 F3 - 4 - 5 - 6 - 16 - 2
10AE27-033/2022 MAE27-010/2021 MMN96-034/2021 F3 - 4 - 12
114AE27-037/2022 FMN96-005/2021 MAE27-068/2021 FAE27-033/2022 MAE27-010/2021 MMN96-034/2021 F4 - 12 - 3
12MN96-008/2021 MMN96-002/2020 MMN96-020/2020 F4 - 5 - 6 - 16 - 2 - 3
13AE27-069/2023 MAE27-018/2022 MMN96-045/2022 F4 - 8 - 2 - 3
145AE27-038/2022 FMN96-005/2021 MAE27-068/2021 FMN96-020/2023 MMN96-011/2022 MMN96-020/2021 F5 - 6 - 9
15AE27-010/2021 MAE27-015/2020 MAE27-021/2020 F5 - 11 - 16
16MN96-008/2021 MMN96-002/2020 MMN96-020/2020 F5 - 6 - 16 - 2 - 3 - 4
176MN96-045/2022 FMN96-002/2020 MMN96-020/2020 FAE27-036/2023 MMN96-024/2021 MAE27-011/2022 F6 - 14
18MN96-020/2023 MMN96-011/2022 MMN96-020/2021 F6 - 9 - 5
19MN96-008/2021 MMN96-002/2020 MMN96-020/2020 F6 - 16 - 2 - 3 - 4 - 5
207MN96-007/2023 FMN96-014/2022 MMN96-021/2021 FAE27-022/2022 MAE27-049/2021 MAE27-003/2021 F7 - 10 - 1
213024-060/2023 M3024-066/2020 M2207-032/2020 F7 - 12 - 13
22
238AE27-009/2023 FAE27-022/2022 MMN96-010/2021 FAE27-018/2022 MMN96-005/2021 MAE27-068/2021 F8 - 15
24AE27-035/2022 MMN96-005/2021 MAE27-068/2021 F8 - 2
25AE27-069/2023 MAE27-018/2022 MMN96-045/2022 F8 - 2 - 3 - 4
269AE27-010/2023 FAE27-022/2022 MMN96-010/2021 FAE27-019/2022 MMN96-005/2021 MAE27-068/2021 F9 - 14 - 16
27MN96-020/2023 MMN96-011/2022 MMN96-020/2021 F9 - 5 - 6
28
2910AE27-015/2023 FMN96-008/2021 MAE27-037/2022 FAE27-022/2023 MAE27-022/2022 MMN96-010/2021 F10 - 15
30AE27-022/2022 MAE27-049/2021 MAE27-003/2021 F10 - 1 - 7
31
3211AE27-017/2023 FMN96-008/2021 MAE27-037/2022 FAE27-010/2021 MAE27-015/2020 MAE27-021/2020 F11 - 16 - 5
335919-001/2023 M3024-058/2020 M3024-011/2022 F11 - 13 - 1
34
3512AE27-019/2023 FAE27-022/2022 MMN96-010/2021 F3024-060/2023 M3024-066/2020 M2207-032/2020 F12 - 13 - 7
36AE27-033/2022 MAE27-010/2021 MMN96-034/2021 F12 - 3 - 4
37
3813AE27-020/2023 FAE27-022/2022 MMN96-010/2021 F5919-001/2023 M3024-058/2020 M3024-011/2022 F13 - 1 - 11
393024-060/2023 M3024-066/2020 M2207-032/2020 F13 - 7 - 12
40
4114AE27-023/2023 FAE27-022/2022 MMN96-010/2021 FAE27-036/2023 MMN96-024/2021 MAE27-011/2022 F14 - 6
42AE27-019/2022 MMN96-005/2021 MAE27-068/2021 F14 - 16 -9
43
4415MN96-027/2023 FAE27-001/2022 MMN96-043/2022 FAE27-022/2023 MAE27-022/2022 MMN96-010/2021 F15 - 10
45AE27-018/2022 MMN96-005/2021 MAE27-068/2021 F15 - 8
46
4716AE27-055/2023 FMN96-046/2019 MMN96-010/2021 FMN96-008/2021 MMN96-002/2020 MMN96-020/2020 F16 - 2 - 3 - 4 - 5 - 6
48AE27-010/2021 MAE27-015/2020 MAE27-021/2020 F16 - 5 -11
49AE27-019/2022 MMN96-005/2021 MAE27-068/2021 F16 - 9 14
50
Croissement
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Give this a try with a copy of your data.

VBA Code:
Sub SubjectGroups()
  Dim d As Object
  Dim a As Variant, b As Variant
  Dim i As Long
  Dim CurrGroup As String
  
  Set d = CreateObject("Scripting.Dictionary")
  a = Range("A2", Range("F" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a), 1 To 1)
  For i = 1 To UBound(a)
    If Len(a(i, 1)) > 0 Then CurrGroup = a(i, 1)
    If Len(a(i, 6)) > 0 Then d(a(i, 6)) = d(a(i, 6)) & " - " & CurrGroup
  Next i
  For i = 1 To UBound(a)
    If Len(a(i, 6)) > 0 Then b(i, 1) = Mid(d(a(i, 6)), 4)
  Next i
  With Range("J2").Resize(UBound(b))
    .NumberFormat = "@"
    .Value = b
  End With
End Sub
 
Upvote 0
Solution
Hello Peter_SSs,
Thanks for your feedback.
Just one word, you are ingenious, your code meets my expectations, gives me the desired result and completely satisfies me, plus it is very fast. Well done again.
Friendships.
 
Upvote 0
You are welcome. Thanks for the follow-up. .. and your kind words. :)
 
Upvote 0
Hello Peter_SSs,
I tested your code, on with groups of 4 lines and more, the code works well too, thank you.
Can you please write a macro that could color the groups with different colors (preferably light colors, that way I can distinguish the groups more easily.
Do not modify the existing code which indicates the groups but create a new macro which colors the various groups.
Thanks in advance
 
Upvote 0
Try this as a start. I have assumed less than about 50 groups. If more a different approach would be needed.

VBA Code:
Sub Colour_Groups()
  Dim r As Long, ClrIdx As Long
  
  Application.ScreenUpdating = False
  ClrIdx = 2
  For r = 2 To Range("F" & Rows.Count).End(xlUp).Row
    If Len(Range("A" & r).Value) > 0 Then ClrIdx = ClrIdx + 1
    Rows(r).Resize(, 8).Interior.ColorIndex = ClrIdx
  Next r
  Application.ScreenUpdating = True
End Sub

(preferably light colors, ..
If you don't like the colours from the above code, perhaps we could choose a few different light colours (example say five of them) and cycle through those colours so they might get used several times (but not next to each other). Does that sound acceptable?
 
Upvote 0
Hello Peter_SSs,
Thank you for your feedback, the code proposed is PERFECT, it suits me completely.
Here, it's 2:00 a.m., I'm going to bed and wishing you a good day, if it's daytime where you live, or a good night if you're in the evening.
Friendships.
 
Upvote 0
You're welcome. Glad it worked for you. Thanks for the confirmation. :)
 
Upvote 0

Forum statistics

Threads
1,223,883
Messages
6,175,167
Members
452,615
Latest member
bogeys2birdies

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