+ Reply to Thread
Results 1 to 6 of 6

Calculate a variable by many conditions

  1. #1
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Calculate a variable by many conditions

    Hello everyone
    I have a variable named 'c' and I need to calculate another variable named 'k' according to the following

    If c < 100 then k=c
    If c >=100 And c<200 then k=c -100
    If c >=200 And c<300 then k=c-200
    If c >=300 And c<400 then k=c-300
    and so on ... till 5000

    I know how to use IF and select case but I am searching for a better and easier way for that .. and I am sure there is a way
    Thanks advanced for help
    Last edited by YasserKhalil; 07-17-2017 at 09:37 AM.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Calculate a variable by many conditions

    Hi,

    To clarify, if c = 99, then k = 99; if c = 199, then k = -99; if c = 299 then k = -99?
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Calculate a variable by many conditions

    Quote Originally Posted by xlnitwit View Post
    Hi,

    To clarify, if c = 99, then k = 99; if c = 199, then k = -99; if c = 299 then k = -99?
    Hello xlnitwit for reply and I am sorry for my bad explanation. I have edited the first post .. It would be positive not negative

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Calculate a variable by many conditions

    It appears you simply need
    Please Login or Register  to view this content.

  5. #5
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Calculate a variable by many conditions

    Or perhaps
    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Calculate a variable by many conditions

    Quote Originally Posted by xlnitwit View Post
    It appears you simply need
    Please Login or Register  to view this content.
    Thanks a lot for this simple and effective solution. I didn't think of it at all

    Thanks a lot Mr Cytop for your solution too but I got the correct results from this line
    k=c Mod 100

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. IF statement with variable # of conditions
    By pulsar777 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-29-2015, 11:44 AM
  2. [SOLVED] Calculate average of variable number of cells variable number of times
    By WeirnetherlandsBart in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-06-2014, 10:11 AM
  3. Replies: 4
    Last Post: 05-07-2014, 03:08 AM
  4. [SOLVED] Calculate sum with conditions
    By bigband1 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 12-30-2012, 12:53 PM
  5. Calculate according to conditions
    By ianmorris1977 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-01-2008, 10:58 AM
  6. Calculate according to conditions
    By ianmorris1977 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 11-30-2008, 04:18 PM
  7. Subtracting - variable conditions
    By Bodz in forum Excel General
    Replies: 4
    Last Post: 07-26-2008, 12:55 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