+ Reply to Thread
Results 1 to 10 of 10

Nest IF statement works on first if only

  1. #1
    Registered User
    Join Date
    07-24-2019
    Location
    Australia
    MS-Off Ver
    2013
    Posts
    7

    Nest IF statement works on first if only

    Hi all,
    I am totally new to VBA and am slowing learning.
    I use a user form to enter data into my database sheet (all works well)
    I use the below code to copy value of K2 (eg) to S2 but is dependent on the value of cell R2.
    It stops after the first If statement.
    This macro is assigned to a user form command button

    What am I not doing right?


    Please Login or Register  to view this content.
    Last edited by Bruce Murphy; 12-19-2020 at 04:13 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,974

    Re: Nest IF statement works on first if only

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional. As you are new, I have done this for you today.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    07-24-2019
    Location
    Australia
    MS-Off Ver
    2013
    Posts
    7

    Re: Nest IF statement works on first if only

    Sorry,
    I though I had done that.
    Thank you for doing it
    Bruce

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,974

    Re: Nest IF statement works on first if only

    You had tried, but didn't apply the tags correctly.

  5. #5
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: Nest IF statement works on first if only

    Hi
    Actually, nothing wrong in you code
    So as I understand the issue you should use

    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: Nest IF statement works on first if only

    And Try may this code
    Please Login or Register  to view this content.

  7. #7
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: Nest IF statement works on first if only

    Quote Originally Posted by Bruce Murphy View Post
    It stops after the first If statement
    I just tried your code & it is working as expected although I would've written it in a different way like below ... If none of the posted solutions is giving you the desired results, they you may need to post a sample file to assist you further

    Please Login or Register  to view this content.
    Note that you're not linking the cell addresses to the defined sheet 'Database'
    Last edited by nankw83; 12-19-2020 at 05:53 AM.
    If I was able to help, you can thank me by clicking the * Add Reputation under my user name

  8. #8
    Registered User
    Join Date
    07-24-2019
    Location
    Australia
    MS-Off Ver
    2013
    Posts
    7

    Re: Nest IF statement works on first if only

    Thanks for the help all.
    I changed to mohadin suggested code which worked as expected
    Don't know why mine wouldn't work the way I wanted it to
    but problem solved
    Thanks to all who took time to assist me - very much appreciated
    Last edited by Bruce Murphy; 12-20-2020 at 03:57 AM. Reason: SOLVED

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,974

    Re: Nest IF statement works on first if only

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  10. #10
    Valued Forum Contributor
    Join Date
    06-27-2010
    Location
    sYRIA
    MS-Off Ver
    Excel 2013
    Posts
    669

    Re: Nest IF statement works on first if only

    @ Bruce Murphy
    Glad I could help
    And thank you for the feed back
    Be happy

+ 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. how to use nest if statement in excel or better way instead ?
    By eddie01001 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-05-2019, 02:56 PM
  2. Replies: 3
    Last Post: 04-15-2019, 12:27 AM
  3. Nest IF statement trouble
    By UWBadger in forum Excel General
    Replies: 1
    Last Post: 09-19-2018, 12:23 PM
  4. Nest if statement with Do while loop
    By cajand in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-16-2015, 08:23 AM
  5. Problem trying to nest IF statement
    By club rat in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 02-24-2014, 12:15 PM
  6. Nest Min in If statement
    By erock24 in forum Excel General
    Replies: 6
    Last Post: 06-20-2007, 11:20 AM
  7. Nest IF statement workaround
    By [email protected] in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-26-2006, 11:35 AM

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