Forum Discussion
How to group automatically in excel
- May 25, 2022
Sekoleyte Interesting. So I found an easier and better way to do the WBS level:
=(SEARCH(LEFT(TRIM(B2),1),B2)-1)/2+1This version will NOT be affected by extra spaces at the end or in the middle 🙂
I also created a macro to automatically do the grouping based on whichever column you highlight:
Public Sub CreateGrouping() '(Optional c As Range) ', Optional UseSpaces = 0) Dim i, r, g As Integer Dim cc As Range If VarType(c) = vbObject Then Set cc = c Else Set cc = Selection End If r = Intersect(cc, ActiveSheet.UsedRange).Rows.Count 'use intersect incase they pass entire column For i = 1 To r If IsNumeric(cc.Cells(i, 1).Value2) Then g = cc.Cells(i, 1).Value2 j = i + 1 If cc.Cells(j, 1) > g Then Do While (cc.Cells(j + 1, 1).Value2 > g) And (j < r) j = j + 1 Loop Range(cc.Cells(i + 1, 1), cc.Cells(j, 1)).EntireRow.Group End If End If Next i End Sub
Sekoleyte Counting leading spaces is not what would come into my mind when I look at the file you uploaded. Why not just look for the occurrence of numbers 1 to 7 in the first 15 characters if the WBS string. Then you could use something like:
=SUM((IFERROR(FIND({1,2,3,4,5,6,7},B3),15)<14)*COLUMN($A$1:$G$1))
...to calculate the level in column A, without the need for the helper table. File attache with the above formula tin column C.
- SekoleyteMay 22, 2022Iron Contributor
Hi Riny_van_Eekelen
Thanks for your effort.
We don't look for occurence of numbbers because they are names i created to prevent confusion but it made a confusion xD
I think you missed my note that i have added my discussion since I guessed that the namings I have given may be misleading. it was that:
"Note: In the file that i shared with you, i created activity names in shape that " Xth WBS Level Activity Name Y" to fit with the WBS levels. Real names don't include WBS level in the activity names."
I mean real activity names don't include WBS level. I don't know if i say it wrong or not in English. Think it like that, instead of " 2nd WBS Level Activity Name", it is actually " Construction Works". Hope i didn't misunderstood what you want to say xD- Riny_van_EekelenMay 22, 2022Platinum Contributor
Sekoleyte Yeah!, I misunderstood. Sorry.