+ Reply to Thread
Results 1 to 8 of 8

Add condition to this code

  1. #1
    Forum Contributor
    Join Date
    07-22-2012
    Location
    Spain
    MS-Off Ver
    Excel 2003
    Posts
    297

    Add condition to this code

    Hi,

    The following takes from Range("B17:B4516") the unique values avoiding blank cells and displays them in a dropdownlist of a userform:

    Please Login or Register  to view this content.
    What I am looking for but cannot manage to do is to put an extra condition. This condition is to avoid also showing data from Range("B17:B4516") when the value from Range("J17:J4516") is higher than 5.

    Any help would be much appreciated.

    Kind regards,

  2. #2
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Add condition to this code

    How about:
    Please Login or Register  to view this content.

  3. #3
    Forum Guru
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,445

    Re: Add condition to this code

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    07-22-2012
    Location
    Spain
    MS-Off Ver
    Excel 2003
    Posts
    297

    Re: Add condition to this code

    Hi!

    I tried both codes and its almost working! Thanks for this help.

    @yudlugar, yours works perfect the only thing is that its not displaying the unique values, the part .exists(v) is the one that is not going...

    @AB33, yours is also working but for some reason it displays more values than the ones I have... something strange... I think its something related to

    Please Login or Register  to view this content.
    That maybe is taking into account more data...

    Thanks once again for helping on this.

    Regards,

  5. #5
    Forum Guru
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,445

    Re: Add condition to this code

    Not,
    Your range is now extended to column J, but testing the same column which is column B.

    Please Login or Register  to view this content.
    is looping down through rows which is the same as you had

    Please Login or Register  to view this content.
    .
    All I have done is convert the range in to an array which is much faster than looping through each range.
    I have not change anything except adding another condition, which now tests column J while your last code only tests column B.
    If you look my range is not longer the same as the old one

    Please Login or Register  to view this content.

  6. #6
    Forum Guru
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,445

    Re: Add condition to this code

    One of these codes work for you, but you need to change the OR and AND. I am not sure which is right for you.
    My preference is the last(3rd) code with swapping the OR and AND if necessary

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: Add condition to this code

    For my code I guess you could try changing .exists(v) to .exists(v.value) but not sure if it would make a difference. Can't see why else it wouldn't work.

  8. #8
    Forum Contributor
    Join Date
    07-22-2012
    Location
    Spain
    MS-Off Ver
    Excel 2003
    Posts
    297

    Re: Add condition to this code

    Hello!!

    Sorry I have been out for a few days... They are both working great!
    I guess I was doing something wrong before...

    I really appreciate your help!!

    Thankss!

+ 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