Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

deleting rows from listbox based on search term criteria

Posted on 2014-04-29
8
Medium Priority
?
189 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 28

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 53

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
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.

 
LVL 3

Author Comment

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

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 53

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

This article describes a serious pitfall that can happen when deleting shapes using VBA.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

926 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