+ Reply to Thread
Results 1 to 9 of 9

Missing occurence for IF statement

  1. #1
    Forum Contributor
    Join Date
    09-02-2013
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    368

    Missing occurence for IF statement

    Hello,

    I've got the following vba code, which purpose is to paste the content of a userform to a worksheet. However, the code checks first if no duplication exists. If it finds duplication, then it gives a message box warning, to which case the user can either cancel or continue.

    The issue I have is that I think I'm missing a piece of statement which action should be similar to the one if the answer is yes from the duplication warning, i.e., if there is no duplication at all, then ... (it looks to me that this is missing but unsure where to put it).

    I'm hoping you can assist and enlighten me.

    Thank you so much.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,361

    Re: Missing occurence for IF statement

    This line:
    Please Login or Register  to view this content.
    Is easier to understand as:
    Please Login or Register  to view this content.
    With that in mind the above if would need an: Else

    See below:
    Please Login or Register  to view this content.
    If things don't change they stay the same

  3. #3
    Forum Contributor
    Join Date
    07-08-2008
    Location
    New York City
    MS-Off Ver
    2013-2016
    Posts
    157

    Re: Missing occurence for IF statement

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    09-02-2013
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    368

    Re: Missing occurence for IF statement

    Thank you. Would I be right to suggest then that I will have to re-write the same code as if the answer to the duplication to continue is Yes, that is,
    Please Login or Register  to view this content.
    So this will be duplicated in the whole code. I hope what I'm saying makes sense

  5. #5
    Forum Contributor
    Join Date
    07-08-2008
    Location
    New York City
    MS-Off Ver
    2013-2016
    Posts
    157

    Re: Missing occurence for IF statement

    If I understand your question, the answer is no.
    In the area after "Else" you simply write what you want to do if there's no duplication.

  6. #6
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,361

    Re: Missing occurence for IF statement

    The below line will only fire if there are duplicates:
    Please Login or Register  to view this content.
    If there are no duplicates then it will go to:
    Please Login or Register  to view this content.
    The way I see it: It is offering to still run code if there are duplicates (Yes/ No), if there are no duplicates then it would not need to ask about duplicates?

  7. #7
    Forum Contributor
    Join Date
    09-02-2013
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    368

    Re: Missing occurence for IF statement

    That's correct indeed. So if there is no duplicate then values in the userform will be copied straight to the worksheet, similar to if the answer to the duplicate question was Yes. the purpose of the duplicate check here is just to alert the user that an entry already exists for the same unique value.

    Therefore, my question is, should I just re-write the same code as if I was answering to Yes to the duplicate check (since there was no difference between the two except one alerts that there is duplicate entry)? If so, is there any way I can simplify the process without re-write the same code twice?

  8. #8
    Forum Expert CheeseSandwich's Avatar
    Join Date
    12-22-2021
    Location
    Kent, England
    MS-Off Ver
    365 - 2402-17328.20068
    Posts
    1,361

    Re: Missing occurence for IF statement

    Hmm not sure I fully understand, is it something like the below:
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    09-02-2013
    Location
    London
    MS-Off Ver
    Excel 2019
    Posts
    368

    Re: Missing occurence for IF statement

    Exactly what's I'm look for. Thank you so much.

+ 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 missing segment
    By Dan190984 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-04-2021, 10:03 PM
  2. missing somethingin this statement
    By i2trader in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 04-06-2016, 05:57 PM
  3. IF Statement and Vlookup Formula....something small missing!! HELP!
    By Nicole Matthews in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-22-2014, 11:34 AM
  4. [SOLVED] IF statement missing parenthesis in formula
    By Abyrose in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-15-2014, 06:24 PM
  5. [SOLVED] What is wrong with my code here? (Missing IF or End Sub statement?)
    By Brookshire in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-23-2013, 01:32 PM
  6. Replies: 2
    Last Post: 03-21-2012, 12:28 PM
  7. If Statement in Function code, what is missing?
    By ChicPea in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-22-2009, 03:33 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