+ Reply to Thread
Results 1 to 7 of 7

Macro for listbox items to be added as per criteria

  1. #1
    Registered User
    Join Date
    11-13-2003
    Location
    India
    MS-Off Ver
    2007
    Posts
    65

    Macro for listbox items to be added as per criteria

    I want to add the items in listbox having criteria of hrs <=50 and >=40 in data,all items has to display in listbox
    Every time when I change cell F2 i.e. "hrs "and its criteria , a macro has to delete old list items and add new items as mentioned in above fashion as per "hrs" criteria
    see attached file-
    Attached Files Attached Files
    mast

  2. #2
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Macro for listbox items to be added as per criteria

    hi
    i have added a list box and button to your sheet and the following code

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  3. #3
    Registered User
    Join Date
    11-13-2003
    Location
    India
    MS-Off Ver
    2007
    Posts
    65

    Re: Macro for listbox items to be added as per criteria

    Hi
    Sean Thomas
    Thanx, what ever you coded is working fine , little more addition to the same list box

    If the J17 to J27 >0 then check same criteria and then add in the listbox
    including the value in 5th column like J17=2 (which is >0)then do the same old for loop but add J17 value in 5th column to all items which is matching the criteria then go to J18 =-5 then leave it then go to J19=5 then again do same old for loop add value of J19 to 5th column and so on.. see attached file for more clarification
    Thanx in advance

    J17
    2
    -8
    5
    0
    0
    -1
    9
    6
    4
    9
    8
    9
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    11-13-2003
    Location
    India
    MS-Off Ver
    2007
    Posts
    65

    Re: Macro for listbox items to be added as per criteria

    Sorry I attached incomplete file see attached here as criteria will be different every time which row value >0 the same row > and < criteria has to be consider

    Criteria
    2 -23.1 -15.1
    -8 -15.1 -7.1
    5 -7.1 0.9
    0 0.9 8.9
    0 8.9 16.9
    -1 16.9 24.9
    9 24.9 32.9
    6 32.9 40.9
    4 40.9 48.9
    9 48.9 56.9
    8 56.9 64.9
    9 64.9 72.9
    Attached Files Attached Files

  5. #5
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Macro for listbox items to be added as per criteria

    I think this is what you mean
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    11-13-2003
    Location
    India
    MS-Off Ver
    2007
    Posts
    65

    Re: Macro for listbox items to be added as per criteria

    Hi sean ,
    thanx for replay but pl. refer latest attached file where I mentioned "sorry " in my last post. ,Don't wast your time I have done it.Thanx for you attention.
    I need help -
    1)Is it possible to add fixed header in activex lisbox to all 5 columns where it is picking data and then add items bellow headers? like..

    |srno| ,|programe no|, |less than or greater than| ,|hrs|,|sum of bases|

    2)Also how to handle the error if any vale having #error or "####" in any cell .

    2
    -8
    #Val or any error due to formula error
    0
    0
    -1
    9
    6
    4
    9
    8
    9

  7. #7
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Macro for listbox items to be added as per criteria

    you can only use headers in a list box if you add a list range that has headers above the columns.
    When you add items using a loop etc you cannot use the headers.
    I usually place the list box below a row and then make the cells above it the same size as your values in the listbox. You can then put your headers above the list box.

    As for your last question

    try adding the line
    Please Login or Register  to view this content.
    above the line
    Please Login or Register  to view this content.

+ 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