+ Reply to Thread
Results 1 to 20 of 20

Value depending upon selection of Listbox data

  1. #1
    Forum Contributor
    Join Date
    01-21-2021
    Location
    Leeds
    MS-Off Ver
    2016
    Posts
    236

    Value depending upon selection of Listbox data

    Thanks for looking at my post

    I have below VB code. Issue is I am doing something wrong in the If statement. When I remove if statement and run one condition at a time it works but when I put if statement with multiple conditions it does not work.

    Any idea of where I am going wrong in the code please?

    Thanks,
    Jim



    HTML Code: 
    Last edited by AliGW; 06-11-2021 at 07:47 AM.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: If statement

    You've nested the Ifs within each other so the second one is tested only if the first one is true (and if that's true, the second one can't be). You can either use:

    Please Login or Register  to view this content.
    or use a Select Case construction:

    Please Login or Register  to view this content.
    Since the loop code is the same other than the column number, you could simplify to:


    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Forum Contributor
    Join Date
    01-21-2021
    Location
    Leeds
    MS-Off Ver
    2016
    Posts
    236

    Re: If statement

    Thanks a lot for your reply. That's work perfect

    Thanks again for your help

    I have one more condition which I need to insert in this loop condition. Sorry to include in my previous post as I just found it.

    I have another textbox named as Textbox1 and its caption is "Available Time". Lets assume I work 8 hrs a day (Monday to Friday). So 40 hrs a week excluding weekends.

    Depending on data like "This Month", "next Month", "Next 3 months", "Next 6 months", "Next 12 month" and "next 24 months" I would like to automatically get number of hrs in the "TextBox1" please.

    That is today is 20/05/2021. So if some one click "This month" I would like to get remaining weekdays of this month multiply by 8. Same for next months (just hold next months data) , next 3 months will hold next 3 months weekdays multiple by 8 and so on.

    Is this complicated?

    Thanks again

    Jim
    Last edited by jimpatel1993; 05-20-2021 at 07:03 AM.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: If statement

    That's a totally separate question and should be asked as such, please.

  5. #5
    Forum Contributor
    Join Date
    01-21-2021
    Location
    Leeds
    MS-Off Ver
    2016
    Posts
    236

    Re: If statement

    Sure

    Thanks
    Jim

  6. #6
    Forum Contributor
    Join Date
    01-21-2021
    Location
    Leeds
    MS-Off Ver
    2016
    Posts
    236

    Value depending upon selection of Listbox data

    Hi,

    Sorry for reopening this thread again. I have modified userform and instead of combobox I have replaced with List box. That is
    HTML Code: 
    where Machine is now List box. Unfortunately the code is not working if I replace with List box. Any idea please?

    Thanks,
    Jim
    Last edited by jimpatel1993; 06-10-2021 at 06:41 AM.

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: If statement

    Define "not working" please. What happens?

  8. #8
    Forum Contributor
    Join Date
    01-21-2021
    Location
    Leeds
    MS-Off Ver
    2016
    Posts
    236

    Value depending upon selection of Listbox data

    Sorry for poor explanation. What I mean is

    1. If machine is combo box then PGNumber textbox is pulling information from column 7 onwards.
    2. If I replace machine (combo box) with listbox then PGNumber textbox is not showing anything when I click anything from listbox.

    I have attached model sheet. Instead of partnumber (which is in combo box) I am trying to get those information in list box which I have highlighted in green.

    NOTE: I have not inserted any code in listbox in this model but when I tried in my actual model I am not seeing any value in PGNumber textbox which is "Total Quantity" in the userform.

    I can explain more if you need more information


    Thanks,
    Jim
    Attached Files Attached Files
    Last edited by jimpatel1993; 06-10-2021 at 06:41 AM.

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,998

    Re: If statement

    I can't debug the code if it's not there...

  10. #10
    Forum Contributor
    Join Date
    01-21-2021
    Location
    Leeds
    MS-Off Ver
    2016
    Posts
    236

    Value depending upon selection of Listbox data

    Sorry for not providing code

    I have attached the sheet with Listbox. I am doing something wrong can you please point me that?

    1. Irrespective of selection in the List box, I am getting same value in "Total time", "Longest Mins", "Shortest Mins" and "longest minus shortest" textbox
    2. Secondly, When I select Demand combo box I am getting wrong value in the Total Quantity text box.
    3. Thirdly, reason for changing to Listbox from combo box is I wanted to select multiple items. Is there any possibility if I select multiple items I should get those multiple items value in "Total time", "Longest Mins", "Shortest Mins" and "longest minus shortest" textbox and in "Total Quantity" text box please?

    Sorry for list of questions.

    Again thanks a lot for your kind support

    Thanks,
    Jim
    Attached Files Attached Files
    Last edited by jimpatel1993; 06-10-2021 at 06:42 AM.

  11. #11
    Forum Contributor
    Join Date
    01-21-2021
    Location
    Leeds
    MS-Off Ver
    2016
    Posts
    236

    Value depending upon selection of Listbox data

    Any idea about this please?

    Thanks
    Last edited by jimpatel1993; 06-10-2021 at 06:42 AM.

  12. #12
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,006

    Re: If statement

    Administrative Note:

    We would very much like to help you with your query, however the thread title does not really convey what your request is about. Tell us what you are trying to do, not how you think it should be done.

    Please take a moment to amend your thread title. Make sure that the title properly explains your request. Your title should be explicit and not be generic (this includes function names used without an indication of what you are trying to achieve).

    Please see Forum Rule #1 about proper thread titles and adjust accordingly. To edit the thread title, open the original post to edit and then click on Go Advanced (bottom right) to access the area where you can edit your title.

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    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. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  13. #13
    Forum Contributor
    Join Date
    01-21-2021
    Location
    Leeds
    MS-Off Ver
    2016
    Posts
    236

    Value depending upon selection of Listbox data

    Really sorry about this. I have updated the title and I have provided more details along with code in the excel

    The aim is depending upon selection of part number from Listbox I would like get results populated in frame 2 and 3 please.
    Currently I am getting wrong value in frame 2 and 3.
    I have userform with 3 different sections (Frame 1, 2 and 3).
    Frame 1 : This is having all part numbers. Depending upon the selection in the frame1 list box, frame 2 value will be populated from “Labour time” sheet.
    Example If user select “1” from Frame 1, “Total Time” for this particular part number (only column c and D) will be shown in the total time box. In this case it will be 290. Longest mins from this particular part number will be shown and same for rest of the title in frame 2.
    If user select multiple option in the list box, I would like to get “Total Time”, Longest mins,etc only for selected multiple part number please.

    Secondly, Frame 3 data is coming from “ADDNEW” sheet. Depending upon the part number selection and select Demands selections , “Total Quantity” is the total quantity for particular or list of selected part number please.

    Hope i explained it better. If not please let me know.
    Attached Files Attached Files

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,006

    Re: If statement

    Update the title in the opening post of the thread, please.

  15. #15
    Forum Contributor
    Join Date
    01-21-2021
    Location
    Leeds
    MS-Off Ver
    2016
    Posts
    236

    Re: If statement

    Hi,

    Thanks for your message. I have updated the title but unfortunately I don't know how to update whole title from the beginning of the thread. Can you please let me know or point me the direction for this please.

    Thanks,
    Jim

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,006

    Re: If statement

    Just click on the edit post button and take it from there.

  17. #17
    Forum Contributor
    Join Date
    01-21-2021
    Location
    Leeds
    MS-Off Ver
    2016
    Posts
    236

    Re: If statement

    Unfortunately I don't get Edit post button for my very first post.

  18. #18
    Forum Contributor
    Join Date
    01-21-2021
    Location
    Leeds
    MS-Off Ver
    2016
    Posts
    236

    Re: If statement

    I wanted to delete this post. sorry
    Last edited by jimpatel1993; 06-11-2021 at 05:56 AM.

  19. #19
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2504 (Windows 11 Home 24H2 64-bit)
    Posts
    91,006

    Re: If statement

    Directly below your opening post are three buttons on the right: Edit Post, Reply and Reply With Quote. These appear below EVERY one of your posts in this thread. I really don't know why you are unable to see those buttons, but for the sake of moving this along I will change the title for you today.

    I suggest you think more carefully about thread titles in future to avoid this sort of thing.

  20. #20
    Forum Contributor
    Join Date
    01-21-2021
    Location
    Leeds
    MS-Off Ver
    2016
    Posts
    236

    Re: Value depending upon selection of Listbox data

    Thanks for updating the title. Yea even i dont know why its not showing for some of my post. Only few of my post have Edit options and rest have only reply options. Anyway thanks for renaming it and i will be careful in future with title


    Thanks,
    Jim

+ 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. [SOLVED] IF Statement with Multi-Criteria Statement inside a Data Validation List
    By dharvey1978 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-31-2020, 09:10 PM
  2. [SOLVED] i have an if then statement that works, how to make it work as a with or case statement
    By dmcgov in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 06-03-2016, 03:34 PM
  3. compile error expected line number statement end statement
    By mattress58 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-18-2014, 10:12 AM
  4. VBA Compile Error : line number or label or statement or end of statement
    By excellearner121 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-04-2013, 06:41 PM
  5. Replies: 4
    Last Post: 06-01-2012, 10:05 AM
  6. Replies: 4
    Last Post: 05-16-2012, 05:33 PM
  7. [SOLVED] Utilize a Select Case Statement in Target Intersect Statement
    By max57 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-29-2009, 08:55 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