Solved

deleting rows from listbox based on search term criteria

Posted on 2014-04-29
8
187 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 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 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

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;…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

615 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