Hi there!
I hope someone can help me. In order for it to be easier to explain, I attach a file that is from my current work in which I need your help. In the attached file, there is a sheet called "Origin" that is how I have the file. And then there is a sheet called "Result" that is what I need to achieve.
Now my explanation:
On column "H" there are a huge ammount of cells which contain some codes of mine: "CAP"; "T"; "P" and finally "OC". These create a tree of sorts, something like this:
T
*P
**OC
**OC
**OC
*P
**OC
**OC
*P
**OC
**OC
**OC
**OC
The number of "OC" varies greatly depending of each "P".
I need a macro that will GROUP (NOT HIDE) every "OC", under it's "P", something like "Selection.Rows.Group"
I have another macro on my sheet that I use to give me the sum of each "CAP" and I know it can be used for what I need now, but I just don't have the vba knowledge to adapt it to my new need. Maybe it could be the base for my help. It goes like this:
Dim rFind As Range
Dim rNext As Range
Set rFind = Range("H:H").Find("OC", LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False) 'it used to say "Find("CAP", but now it has to look for "OC"
Do While Not rFind Is Nothing
Set rNext = Range(rFind.Offset(1), Cells(Rows.Count, "H")).Find("OC")
If Not rNext Is Nothing Then
Cells(rFind.Row, "N").FormulaR1C1 = Replace("=sum(r[1]c:r[@]c)", "@", rNext.Row - rFind.Row - 1)
Else
Cells(rFind.Row, "N").FormulaR1C1 = Replace("=sum(r[1]c:r[@]c)", "@", Rows.Count - rFind.Row - 1)
End If
Set rFind = rNext
Loop
Thank you for your time.
*EDIT: placed the code tags
Bookmarks