Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

deleting rows from listbox based on search term criteria

Posted on 2014-04-29
8
Medium Priority
?
188 Views
Last Modified: 2014-05-08
excel vba 2010
userform listbox32
userform textbox33

What I have:
I have a textbox33 I'm allowing people to type in a search term to see if it exists in 2 columns in the listbox.(terms SEPERATED BY A  ;  

So a textbox33 could contain
RED;10;WOOD;


code:
strFilter = Split(TextBox33.Text, ";")
For lngIndex = ListBox32.ListCount - 1 To 0 Step -1
    bFound = True

    For lngPart = 0 To UBound(strFilter) ' VALUES TO SEARCH FOR
       ' assuming bfound is still true
      If InStr(1, UCase(ListBox32.List(lngIndex, 3)), UCase(strFilter(lngPart))) = 0 Or InStr(1, UCase(ListBox32.List(lngIndex, 4)), UCase(strFilter(lngPart))) = 0 Then
                                bFound = False
                                Exit For
                             End If
                           
    If Not bFound Then
        ListBox32.RemoveItem (lngIndex)
    End If
Next

Open in new window



What I need:
if a person types in more than 1 search term. The code becomes more complicated.
Basically, I need this.
All 3 search terms  has to exist in both columns.
right now i'm using an OR

so  in this case "RED;10;WOOD;"  would have to exist in both columns in all rows.
if any of the terms do not exist in either column.
that row gets deleted from the listbox.


it may be as simple as changing the operator to an "AND" ??

just trying to make sure.


thanks
fordraiders
0
Comment
Question by:fordraiders
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 27

Accepted Solution

by:
MacroShadow earned 2000 total points
ID: 40031235
it may be as simple as changing the operator to an "AND" ??

yes it is!
0
 
LVL 3

Author Comment

by:fordraiders
ID: 40031247
ok, but let me explain again..

Listbox32  columns 3  and   4

Column 3                                         Column 4
AIR TUBING 1/2 X 3/4 COPPER        AIR TUBING 1/2 X 3/4 COPPER 722 PRESSURE
TUBING 1/2 X 1/2 WROT                 AIR TUBING 1/2 X 1/2 WROT COPPER 322 PSI
TUBING 3/4 X 7/16                          TUBING 3/4 X 7/16 WROT 322 PSI

if my search terms were:
1/2;WROT

then row 1 would be the only row to get deleted:
because even though 1/2 exists in column 3 and 4
WROT does not exist in  column 3 and 4


Thanks
fordraiders
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 40031312
Hi

In your example you say that line 3 should not be deleted  but hasn't 1/2

Could you explain?

Regards
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Author Comment

by:fordraiders
ID: 40031779
because it has the word "wrot" in column 4
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 40036542
You say that line 3 should not be deleted because it has WROT but not 1/2

so Why line 1 should be deleted if it has 1/2 and not WROT

Regards
0
 
LVL 3

Author Comment

by:fordraiders
ID: 40037040
sorry line 3 should be deleted also...my fault.
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 40037065
So I do not see the problem in your code

it triggers a delete as soon as it doesn't find one of the search terms in any of the columns

Isn't it what you want?

Regards
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 40050742
Thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question