+ Reply to Thread
Results 1 to 8 of 8

Select Case with Loop or For Next

  1. #1
    Forum Contributor
    Join Date
    07-28-2009
    Location
    Orange County, CA
    MS-Off Ver
    Excel 2007
    Posts
    115

    Select Case with Loop or For Next

    Simplifying multiple IF-Then while maintaining one macro.

    How can i simplify this? This is only 2 of 5, idealy i want this to do exactly what it's doing, checking to see what value is in the cells B5:B9

    There has to be an easier way.

    Please Login or Register  to view this content.
    Last edited by garretonufer; 09-23-2009 at 09:02 PM.

  2. #2
    Forum Expert
    Join Date
    03-23-2004
    Location
    London, England
    MS-Off Ver
    Excel 2019
    Posts
    7,064

    Re: Simplifying multiple IF-Then

    You should be able to remove pretty much ALL of them IFs and replace with one line,something based on (I am NOT a VBA programmer)

    Range("G" & Range("B5").Value +15 ) = Range("G" & Range("B5").Value +15 ) + 1

    since the row number of G is always 15 more than the value in B
    Regards
    Special-K

    Ensure you describe your problem clearly, I have little time available to solve these problems and do not appreciate numerous changes to them.

  3. #3
    Forum Contributor
    Join Date
    07-28-2009
    Location
    Orange County, CA
    MS-Off Ver
    Excel 2007
    Posts
    115

    Re: Simplifying multiple IF-Then

    This is actually a test formula, i plan on the end result, increasing a cell on a different sheet, but per the example, the B5-B9 will be repeated later, so another table will be evaluated with a dublicated macro so lets say B12-B16 however the end results won't change. the value to be increased will be a fixed range of say Sheet1.Range("D17:D24")

    i'm just trying to understand the basics of the macro so that i can tweek it for the ultimate goal. I like the thought though and may very well try to impliment that.

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Simplifying multiple IF-Then

    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  5. #5
    Valued Forum Contributor
    Join Date
    10-15-2007
    Location
    Home
    MS-Off Ver
    Office 2010, W10
    Posts
    373

    Re: Simplifying multiple IF-Then

    Hi

    For B5:B9, try:

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    07-28-2009
    Location
    Orange County, CA
    MS-Off Ver
    Excel 2007
    Posts
    115

    Re: Simplifying multiple IF-Then

    Quote Originally Posted by martindwilson View Post
    I'll take a look, thanks.

  7. #7
    Forum Contributor
    Join Date
    07-28-2009
    Location
    Orange County, CA
    MS-Off Ver
    Excel 2007
    Posts
    115

    Re: Simplifying multiple IF-Then

    OK folks so i've moved onto a Select Case set up. But i need a little help with a loop

    I currently have
    Please Login or Register  to view this content.
    This issue is i need this to repeat for cells B32,B33,B34,B35 (B31:B35)

    what would i need to add to this inorder to loop for the next 4 cells in the desired range?

  8. #8
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Select Case with Loop or For Next

    Personally I would do it like this.
    This way if you change the range you want to place the data into it is easy to change at one place in the code, (less prone to typos!)

    Please Login or Register  to view this content.
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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