+ Reply to Thread
Results 1 to 20 of 20

Do more than on action if and IF statement is true

  1. #1
    Registered User
    Join Date
    10-02-2012
    Location
    Galway, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    34

    Do more than on action if and IF statement is true

    Hi,
    I have a macro and in it I have an if statement:
    If MsgBox("Is the correct Part Number (" & aa & ") entered?", vbYesNo) = vbYes _
    Then ee = Application.InputBox("Please enter Vendor Code") _
    Else: Range("C1:D1").ClearContents
    End If

    What I want to add is that when the statement is true, after the message box appears and the Vendor code is entered, I want the macro to put this formula into Cell C6:
    =IF(C4="","",(VLOOKUP(C4,STS!A6:C20000,1,TRUE)))

  2. #2
    Forum Contributor
    Join Date
    10-02-2012
    Location
    Bumi Nusantara
    MS-Off Ver
    Excel 2010; Excel 2016
    Posts
    136

    Re: Do more than on action if and IF statement is true

    try this code

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-02-2012
    Location
    Galway, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Do more than on action if and IF statement is true

    Hi dwint,
    the problem is that I need to have the output from the inputbox ee entered before I can use the vlookup:
    If ee <> 0 Then Range("C6") = ee Else Range("C6") = ""

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Do more than on action if and IF statement is true

    do you mean
    Please Login or Register  to view this content.
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Registered User
    Join Date
    10-02-2012
    Location
    Galway, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Do more than on action if and IF statement is true

    Hi JosephP,
    when I tried the code it runs, prompts to put in the Code but then doesn't put the formula into the cell. Am I wrong in thinking that it is stepping out of the If statement when ee<>0 and once it have put the ee value into C6? See below where dd is a check for occurance of aa:

    If dd Is Nothing Then
    If MsgBox("Is the correct Part Number (" & aa & ") entered?", vbYesNo) = vbYes Then
    ee = Application.InputBox("Please enter Vendor Code")
    If ee <> 0 Then
    Range("C6").Value = ee
    Else
    Range("C4").ClearContents
    End If
    Range("c9").Formula = "=IF(C4="""","""",VLOOKUP(C4,STS!A6:C20000,1,TRUE))"
    Else
    Range("C4:D4").ClearContents
    End If

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Do more than on action if and IF statement is true

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    once you correct that we can continue :-)

    thank you

  7. #7
    Registered User
    Join Date
    10-02-2012
    Location
    Galway, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Do more than on action if and IF statement is true

    Apologies.... See attached:
    Please Login or Register  to view this content.

  8. #8
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Do more than on action if and IF statement is true

    as long as you say yes to the message the formula should be put in c9 no matter what you subsequently enter in the input box

  9. #9
    Registered User
    Join Date
    10-02-2012
    Location
    Galway, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Do more than on action if and IF statement is true

    When I hit Yes, the inputbox comes up... I enter a number, hit OK and then thats all that happens.

  10. #10
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Do more than on action if and IF statement is true

    perhaps you meant to change the code to
    Please Login or Register  to view this content.
    instead of
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    10-02-2012
    Location
    Galway, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Do more than on action if and IF statement is true

    No, maybe I should explain it better. User puts a value into C4, hits a search button. This is the code in that search button where it checks first to see in the value in C4 exists in a list designated by dd. If its not there, it firstly make sure the part entered is correct, if so, it requests a code which it puts into C6 (not sure if I can run the lookup direct from the macro and output the results).

  12. #12
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Do more than on action if and IF statement is true

    are you saying the value does not get put in c6 by the code? can you provide a sample workbook?

  13. #13
    Registered User
    Join Date
    10-02-2012
    Location
    Galway, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Do more than on action if and IF statement is true

    Hi, the code put into the input box gets put into C6, but the If+vlookup formula does not get put into C9. Can provide a sample workbook but not sure how to upload it on this site

  14. #14
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Do more than on action if and IF statement is true

    When you are in Advanced reply, click on the paperclip to open the upload window.

    View Pic

  15. #15
    Registered User
    Join Date
    10-02-2012
    Location
    Galway, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Do more than on action if and IF statement is true

    See Attached.....
    Attached Files Attached Files

  16. #16
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Do more than on action if and IF statement is true

    merged cells :-(

    you need
    Please Login or Register  to view this content.
    not C9

  17. #17
    Registered User
    Join Date
    10-02-2012
    Location
    Galway, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Do more than on action if and IF statement is true

    Thanks JP. I must be losing it......
    Is it possible that when the user hits "No", to run the code in Module 1 without having to try the other search? Ideally would just want the 1 search button.

  18. #18
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Do more than on action if and IF statement is true

    replace
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    10-02-2012
    Location
    Galway, Ireland
    MS-Off Ver
    Excel 2010
    Posts
    34

    Re: Do more than on action if and IF statement is true

    Thank JosephP, you have been very helpful.
    I was curious, is it possible to use .Find instead of lookups to put data in?
    for example, if I put in a part number in C4 that is listed on the STS, output the corresponding code to a designator like ff and then reference ff in a cell?
    If there was more than 1 instance on the part number in C4 with a different vendor code, can this be output into the next row down?

  20. #20
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Do more than on action if and IF statement is true

    yes it is but I suggest that you post that as a new question since it is unrelated to the topic of this one. you'll probably need a bit more detail for a specific answer too ;-)

    please don't forget to mark this thread solved

+ 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