+ Reply to Thread
Results 1 to 4 of 4

create a macro if else statement

  1. #1
    Registered User
    Join Date
    05-26-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    27

    create a macro if else statement

    hi i want to create a macro but im not too sure how for i am quite new in Excel.

    i want this macro to read a value from a cell and from there return a value that i have set to.
    say,
    if A2 = LX1
    return 6;
    else if A2 = UG2,
    return 12;
    .....

    i have arnd 30 values here that return either a 3, 6, 9 or 12.
    any ideas how to start?
    is a switch table more accomodating?
    and furthermore LX1 may have 2 more possibilities that its either a 9 or 12.
    so like
    if A2 = LX1,
    it can either return a 9 or 12.
    how? help!
    Last edited by aysrun; 05-28-2009 at 06:06 AM.

  2. #2
    Registered User
    Join Date
    07-14-2008
    Location
    INDIA
    Posts
    78

    Re: create a macro if else statement

    Can you explain it more like what are the other possibilities etc.,.
    it will be more nice if you post a workbook with dummy data.

  3. #3
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Re: create a macro if else statement

    if A2 = LX1,
    it can either return a 9 or 12.
    You will need to provide more details so the macro code will be able to determine if it is a 9 or the 12 that is to be returned.
    Or do you want the macro to try and guess which one you want returned?

    Where are the values to be returned to

    It is possible that you may be able to acheive what you want from a Vlookup formula
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  4. #4
    Registered User
    Join Date
    05-26-2009
    Location
    Singapore
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: create a macro if else statement

    found a way alr (: thanks.
    i made a macro with 'if-else' statement. and abt the 9 or 12, its not needed yet.
    thanks!!

+ 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