Consulting

Results 1 to 6 of 6

Thread: Solved: Finding and manipulating cell ranges

  1. #1
    VBAX Newbie
    Joined
    Apr 2011
    Posts
    2
    Location

    Solved: Finding and manipulating cell ranges

    To start off with I know very little VBA and I'm not finding many sources of info that will teach me how to do what I'm wanting to do(or maybe I'm not understanding what I'm reading) So I'm hoping someone here can help me. It sounded simple in my mind. lol

    I have a spread sheet with thousands of rows. All of the data in the A column (always starting with Cell A7) it has grouped numbers 100, 200, 700 for each row. The numbers vary but are always grouped and the amount of rows for each group varies as well.

    I'm trying to figure out how you can find the cell range of all 100's. Then sum them up and place it in the last row of 100's F column.

    In this case it would be for the first group range would be A7:A16 and the added data (which should be 1,000) would be placed into F16. And then move onto the next range of numbers which would be 200 repeat the above and then move onto 700 and repeat until the end of the sheet. The rest of the data in the sheet is just for display purposes and shouldn't matter and is varied in actual naming. Everything varies from month to month so the amount of rows, code numbers, and placement of the totals is never in the same row but is always in A and F

    I repeat I don't really know what I'm doing here but I know this can be done it seems so simple and I'm at loss.
    Attached Files Attached Files

  2. #2
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    You don't need VBA you just need to use grouping. If your using 2007 go to the data tab. Highlight your data. Click group and then click subtotal.
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

  3. #3
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    this has had a minimal test but should do what you want (there are smarter ways of doing this )[VBA]Sub Total_Formula()
    Dim Rng As Range, i As Long, Cnt As Long
    i = Range("A" & Rows.Count).End(xlUp).Row
    Do
    Set Rng = Range("A7:A" & Range("A" & Rows.Count).End(xlUp).Row)
    Cnt = Application.WorksheetFunction.CountIf(Rng, Range("A" & i).Value)
    Range("E" & i).Value = Range("A" & i).Value & " Total:"
    Range("F" & i).Formula = "=sum(A" & i + 1 - Cnt & ":A" & i & ")"
    i = i - Cnt
    Loop Until i = 6
    End Sub[/VBA]
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  4. #4
    VBAX Newbie
    Joined
    Apr 2011
    Posts
    2
    Location
    Quote Originally Posted by Simon Lloyd
    this has had a minimal test but should do what you want (there are smarter ways of doing this )
    Thank You! Your a life saver!

    Quote Originally Posted by BrianMH
    You don't need VBA you just need to use grouping. If your using 2007 go to the data tab. Highlight your data. Click group and then click subtotal.
    Wish I could sadly our office computers likely won't see 2007 until 2015

    seriously

  5. #5
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    http://www.ehow.com/how_4499838_grou...oft-excel.html
    Can do it in office 2003 too. Not sure if its available in 97. But if the macro works thats all good too.
    -----------------------------------------
    The more you learn about something the more you know you have much to learn.

  6. #6
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    If this is solved please go to your first post and above it to the right you will see "Thread Tools" in this dropdown there is an option to mark the thread solved
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

Posting Permissions

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