+ Reply to Thread
Results 1 to 3 of 3

for, if, and, end if

  1. #1
    Forum Contributor
    Join Date
    06-29-2011
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    122

    for, if, and, end if

    im trying to achieve the following

    if val a = val b and val a > 5000 then val q = val q
    else
    if val a = val b and val a is between 1000 and 5000 then val q = val q - 0.25
    else
    if val a = val b and val a is between 500 and 1000 then val q = val q - 0.5
    else
    if val a = val b and val a is between 250 and 500 then val q = val q - 0.75
    else
    if val a = val b and val a < 250 then val q = 0


    the first and last statements seem to work but the middle three wont which seems due to the double Ands
    how do i write the properly and is there a way to write the code more economically?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,492

    Re: for, if, and, end if

    I suggest you post a sample workbook with some typical data, the code and instructions on how to make it work/fail.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Canada Eh
    MS-Off Ver
    Excel 2010
    Posts
    199

    Re: for, if, and, end if

    You need to add underscores when using two lines for one line of code:
    Please Login or Register  to view this content.
    Now, I don't know if this actually solves your logical problems but...
    Click the * to give Rep to a post you like.

+ 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