Excel User Group
Microsoft Excel blogs, forums, files. Read, ask questions, provide answers.

Selecting a range of data and running a seperate set of code on each column within that range

Latest post Fri, Jul 23 2010 11:24 AM by TexasDave. 2 replies.
  • Thu, Jul 22 2010 4:51 PM

    • TexasDave
    • Top 50 Contributor
    • Joined on Fri, Jun 26 2009
    • Posts 20
    • Points 340

    Selecting a range of data and running a seperate set of code on each column within that range

    I have a spreadsheet with data sorted into sections which are labeled to show a relation, e.g. section A, section B, etc. (in Column D), each section has a varying number of rows (between 5-150) of data.  Within each section are three columns of data (Column G, H, and I). 

    What I need is something that will search Column D for the first instance of "Section A" (for example D15), which would be the start point, and the last instance of "Section A" (for example D25) which would be the end point.  The actual range of data that I'm interested in would be in G15:I25.

    From there the code would need to run one set of code on G15:G25, another set of code on H15:H25, and a third set of code on I15:I25. 

    My challenge is that each "section" will fluxuate from month to month, increasing and decreasing in size, which means I can't use a "set" range. 

    I've tried to research this online and have tried using named ranges, offset, countif, etc. and haven't been able to make anything work.  I've written the code that I need for each column of data (G, H, and I), I just need help "pointing" it towards the right sections. 

    Hopefully this all makes sense.  I'm self taught, so I'm sure that my failure to make it work is related to some gap of knowledge on my part (there are many, I'm sure).  Any help on this would be greatly appreciated!!!

     

    • Post Points: 21
  • Thu, Jul 22 2010 8:35 PM In reply to

    • Rick Williams
    • Top 25 Contributor
    • Joined on Wed, Jan 9 2008
    • Melbourne, Australia
    • Posts 56
    • Points 951

    Re: Selecting a range of data and running a seperate set of code on each column within that range

    I've attached an example using match, countif and offset to achieve your goal, and also created a named range to demonstrate how this can be used too.

    You could also do the same thing in VBA code, though I'll leave that to someone else for now.

     

    Also, this assumes that your 'sections' are in continuous blocks (i.e. AAAEEEBBC, not AAACDCCBBDDEEAA) because the countif is used to know how large the range should be.

     

     

    Rick Idea
    Melbourne, Australia

    • Post Points: 21
  • Fri, Jul 23 2010 11:24 AM In reply to

    • TexasDave
    • Top 50 Contributor
    • Joined on Fri, Jun 26 2009
    • Posts 20
    • Points 340

    Re: Selecting a range of data and running a seperate set of code on each column within that range

    Thanks Rick, really appreciate the ideas.

    I'm attempting to write all of this in VBA because this will be used by a fairly large number of people with varying degrees of excel knowledge (which sounds funny coming from a guy who's self taught, I know), so I'd like to have everything running in the background. 

    That said, this has taught me a few things I didn't know before, and I'm sure there's a VBA equivalent.  [quick edit - the sections are in continous blocks, "A" will always be grouped together, etc.]

    Thanks again for putting this together!!!!

    Best Regards,

    David

    [quick edit - If anyone has suggestions/comments for a VBA equivalent that'd be great, otherwise it off to the object browser I go!]

    • Post Points: 5
Page 1 of 1 (3 items) | RSS
Copyright Excel User Group and the relevant contributors, 2010. All Trade Marks acknowledged. This site is a peer-to-peer site and NOT affiliated in any way to Microsoft Corp. All rights reserved.