title: Automating group creation
body: <p>I'm trying to write a script to automate creating groups from data being exported from SAP. So the data comes out as follows in the first column with part numbers and descriptions in the following ones.</p>
  
  <pre><code>.1
  ..2
  ..2
  ...3
  ....4
  .1
  .1
  ..2
  </code></pre>
  
  <p>and so on and so forth with <code>1</code> being the highest level and <code>4</code> the lowest raw material level there can be one of each or hundreds of each sub-level. Just one export has 2,000-5,000 components so it's a very tedious process starting out with grouping everything manually. So I've been trying to automate this but keep running into walls. My code is a mess and doesn't really do anything but I'll post what I've done.</p>
  
  <pre><code>    Dim myRange As Range
      Dim rowCount As Integer, currentRow As Integer
      Dim GrpRange As Range, GrpStart As Integer, GrpEnd As Integer, GrpCount As Integer
      Dim GrpLoop As Integer, GrpLoopEnd As Integer, GrpLoopEndRow As Integer 
      Dim GrpSt As Integer
  
  GrpSt = 2
  GrpStart = 2
  GrpEnd = RowEnd(2, 1)
  GrpLoopEnd = 100
  
  'Loop through each group
    'For TotalLoop = 2 To GrpEnd
  
  'Determine 1 to 1 row length
  For GrpStart = GrpSt To GrpEnd
      Cells(GrpStart, 1).Select
      If Right(ActiveCell, 1) = 1 Then
          GrpSt = ActiveCell.Row
          For GrpLoop = 0 To GrpLoopEnd
              If Right(Cells(GrpSt, 1), 1) = 1 Then
                  GrpLoopEnd = 1
                  GrpLoopEndRow = ActiveCell.Row
                  Exit For
              End If
          Next
      End If
  
  Next GrpStart
  </code></pre>
  
  <p>I'm first just trying to find the length between each top level <code>1</code> and the next one, because sometimes there is structure and sometimes not. Next I was going to do the same for the <code>2</code> then <code>3</code> then <code>4</code> within that one "group", then do the grouping and finally loop through the rest of the column and do the same with each "1 to 1" group. I'm not sure if this is the right way or even possible but I had to start from somewhere.</p>
  
  <p>Here's an example of what is exported:</p>
  
  <p><img src="https://i.stack.imgur.com/C1Hky.jpg" alt="SO19009523 first question example"></p>
  
  <p>Here's an example of the grouping I'm looking for:</p>
  
  <p><img src="https://i.stack.imgur.com/WP5iP.jpg" alt="SO19009523 second question example"></p>