Results 1 to 5 of 5

Group an unknown number of rows which start with a given string of text

Threaded View

rcosteira Group an unknown number of... 04-15-2019, 02:36 PM
AliGW Re: [HELP] Group an unknown... 04-15-2019, 05:14 PM
rcosteira Re: [HELP] Group an unknown... 04-16-2019, 05:18 AM
AliGW Re: Group an unknown number... 04-16-2019, 05:23 AM
rcosteira Re: Group an unknown number... 04-17-2019, 05:16 AM
  1. #1
    Registered User
    Join Date
    11-25-2016
    Location
    Portugal
    MS-Off Ver
    Office 365
    Posts
    15

    Group an unknown number of rows which start with a given string of text

    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
    Attached Files Attached Files
    Last edited by rcosteira; 04-16-2019 at 05:16 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] SUM for unknown number of set of rows
    By California4jx in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 12-27-2016, 05:15 PM
  2. [SOLVED] Searching for unknown text string in a range and then matching it to a reference table
    By the_nibs in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 06-10-2015, 07:26 AM
  3. Replies: 2
    Last Post: 07-31-2013, 05:57 PM
  4. Loop to Sum Unknown Number of Rows
    By DBExhale in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-15-2010, 07:19 AM
  5. Sum of Unknown Number of Rows
    By Colin_S in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-12-2010, 11:27 AM
  6. Replies: 4
    Last Post: 08-02-2010, 04:26 PM
  7. sum up an unknown number of rows
    By skoller in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-12-2006, 07:33 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1