+ Reply to Thread
Results 1 to 16 of 16

VBA code to get 3 IF statement to work

  1. #1
    Registered User
    Join Date
    10-05-2012
    Location
    Gainsborough, England
    MS-Off Ver
    Office 2016 & Office 365
    Posts
    87

    VBA code to get 3 IF statement to work

    hi

    Can someone point me in the right direction with a bit of code, I have 3 comboboxes and 1 listbox on a userform, the bit of VBA i want is to
    look at what all 3 selections in the comboboxes so for example.....

    Combobox1 = "word 1"
    Combobox2 = "word 2"
    Combobox3 = "word 3"

    Listbox1 = a certain named range decided by the 3 words selected, I have tried IF statements but can not get 3 Ifs to work
    all I am trying to achieve is

    If Combobox1.value = "word 1" and Combobox.value = "word 2" and Combobox3.value = "word 3" then
    Listbox1.Rowsource = certain named range

    I have tried many variations for IF, And, Rowsource, ListFillRange
    I seem to be struggling on something which I think is very simple

    Thanks
    J

  2. #2
    Forum Contributor
    Join Date
    09-05-2012
    Location
    Dubai
    MS-Off Ver
    Office 365
    Posts
    409

    Re: VBA code to get 3 IF statement to work

    Hi.
    Try this
    replace below NamedRange with your actual name

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    10-05-2012
    Location
    Gainsborough, England
    MS-Off Ver
    Office 2016 & Office 365
    Posts
    87

    Re: VBA code to get 3 IF statement to work

    Thank you naveenmarapaka but that also does not work, it will work with 1 Combobox but when you use (And) and add 2 more into the IF statement it fails to work

  4. #4
    Forum Contributor
    Join Date
    09-05-2012
    Location
    Dubai
    MS-Off Ver
    Office 365
    Posts
    409

    Re: VBA code to get 3 IF statement to work

    Post your sample data

  5. #5
    Registered User
    Join Date
    10-05-2012
    Location
    Gainsborough, England
    MS-Off Ver
    Office 2016 & Office 365
    Posts
    87

    Re: VBA code to get 3 IF statement to work

    Sample Data Attached
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    09-05-2012
    Location
    Dubai
    MS-Off Ver
    Office 365
    Posts
    409

    Re: VBA code to get 3 IF statement to work

    Check this...
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    10-05-2012
    Location
    Gainsborough, England
    MS-Off Ver
    Office 2016 & Office 365
    Posts
    87

    Re: VBA code to get 3 IF statement to work

    Great, thank you, one last thing if I clicked on an item in the Listbox how could I retrieve the data from the row of the item listed ? put into textboxes on userform?
    Thank you for your help
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    09-05-2012
    Location
    Dubai
    MS-Off Ver
    Office 365
    Posts
    409

    Re: VBA code to get 3 IF statement to work

    Hi.
    You binded your Macro to a limited range of data selection...

    I believe basically you want program as attached... Test it fully.....and let me know....



    1 Click on the star if you think some-1 helped you
    2. If your question is resolved, mark it SOLVED using the thread tools
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    10-05-2012
    Location
    Gainsborough, England
    MS-Off Ver
    Office 2016 & Office 365
    Posts
    87

    Re: VBA code to get 3 IF statement to work

    You make it look so easy, Thank you very much

  10. #10
    Forum Contributor
    Join Date
    09-05-2012
    Location
    Dubai
    MS-Off Ver
    Office 365
    Posts
    409

    Re: VBA code to get 3 IF statement to work

    Glad it helped you

  11. #11
    Registered User
    Join Date
    10-05-2012
    Location
    Gainsborough, England
    MS-Off Ver
    Office 2016 & Office 365
    Posts
    87

    Re: VBA code to get 3 IF statement to work

    Hi naveenmarapaka

    Hope you can help again
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    09-05-2012
    Location
    Dubai
    MS-Off Ver
    Office 365
    Posts
    409

    Re: VBA code to get 3 IF statement to work

    Hi. Ken, Slightly modified ... still please specify your requirement....
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    10-05-2012
    Location
    Gainsborough, England
    MS-Off Ver
    Office 2016 & Office 365
    Posts
    87

    Re: VBA code to get 3 IF statement to work

    it is pulling the data from the wrong row, not current row, Please see Attached file with requirements,hope it is a bit more clear, thank you
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    09-05-2012
    Location
    Dubai
    MS-Off Ver
    Office 365
    Posts
    409

    Re: VBA code to get 3 IF statement to work

    Cut this line of code
    Please Login or Register  to view this content.
    at the bottom
    in Prscss_click() module...
    and paste at Prscss_click() module starting and check .....

  15. #15
    Registered User
    Join Date
    10-05-2012
    Location
    Gainsborough, England
    MS-Off Ver
    Office 2016 & Office 365
    Posts
    87

    Re: VBA code to get 3 IF statement to work

    yes that is now working thank you for your time

  16. #16
    Forum Contributor
    Join Date
    09-05-2012
    Location
    Dubai
    MS-Off Ver
    Office 365
    Posts
    409

    Re: VBA code to get 3 IF statement to work

    You are Welcome

+ 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. User Defined Function with If statement, does not work, incorrect code?
    By forrestgump1980 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-07-2014, 09:31 AM
  2. Replies: 9
    Last Post: 08-30-2013, 07:49 AM
  3. Replies: 1
    Last Post: 08-14-2013, 12:01 PM
  4. If Statement USED to Work!
    By Snoopy2010 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-25-2010, 08:12 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