Solved

deleting rows from listbox based on search term criteria

Posted on 2014-04-29
8
179 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
  • 4
  • 3
8 Comments
 
LVL 26

Accepted Solution

by:
MacroShadow earned 500 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 48

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
 
LVL 3

Author Comment

by:fordraiders
ID: 40031779
because it has the word "wrot" in column 4
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 48

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 48

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now