Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

check  3 columns  in a listbox and get a count of occurences for each column

Posted on 2013-11-18
2
Medium Priority
?
350 Views
Last Modified: 2013-11-18
excel 2010 vba

What I have :
Listbox that is filled via an array.
listbox has 23 columns
A variable   "str"

I need to use the variable/value  from a combobox

(The code below is finding the "Like" value in Column 5 if it finds it.
It removes it from the item from the listbox...
I'am showing this as reference.)


What I need:

I need to get a count of   "Like" occurences in Column 5, 13, 19 in the listbox

and return for all three columns the count
cn1 =  2
cn2  = 5
cn3 =  3



If UserForm2.ComboBox1.Value <> "" Then
str = UserForm2.ComboBox1.Value
With UserForm2.ListBox1
    For ri = .ListCount - 1 To 0 Step -1
If Not (LCase(.List(ri, 5)) Like "*" & LCase(str) & "*") Then 'Or Not (LCase(.List(ri, 19)) Like "*" & LCase(str) & "*") Then
             .RemoveItem ri
        End If
    Next
End With
End If


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
2 Comments
 
LVL 53

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 39658534
Hi,

pls try

Sub Macro()
cn1 = 0
cn2 = 0
cn3 = 0

If UserForm2.ComboBox1.Value <> "" Then
Str = UserForm2.ComboBox1.Value
With UserForm2.ListBox1
    For ri = .ListCount - 1 To 0 Step -1
        If LCase(.List(ri, 5)) Like "*" & LCase(Str) & "*" Then
             cn1 = cn1 + 1
        End If
        If LCase(.List(ri, 13)) Like "*" & LCase(Str) & "*" Then
             cn2 = cn2 + 1
        End If
        If LCase(.List(ri, 19)) Like "*" & LCase(Str) & "*" Then
             cn3 = cn3 + 1
        End If
    Next
End With
End If

MsgBox "cn1: " & cn1 & ", cn2: " & cn2 & ", cn3: " & cn3

End Sub

Open in new window

Regards
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 39658548
perfect...Thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

609 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