Solved

Search column for ComboBox Value in column and return Row text

Posted on 2013-01-21
3
278 Views
Last Modified: 2013-02-05
Hi,

I am pretty new to VBA and still learning the ropes as it were.  

I have a userform where staff can select their names from a ComboBox and press a "Cancel Parts Request" button, which would return the last 15 data rows they entered using their Username from the ComboBox to filter on.  

I would like to be able to search for the last 15 (or whatever number) of entries by a user, based on their name, which is entered in Column I and return the text in those rows.

I have been using the find function but I can't get it to recognize the name  in the ComboBox.  This is what I have so far:

Dim rngSearch As Range, rngFound As Range
Set rngSearch = Range("I:I")
Set rngFound = rngSearch.Find(What:="ComboBox1.Value", LookIn:=xlValues, LookAt:=xlPart)
If rngFound Is Nothing Then
MsgBox "No Parts Request Found"
Else
MsgBox rngFound.Row
End If

I keep getting the "No Parts Request Found" message no matter what name is entered in ComboxBox1.  Also I have no idea how to search for the last 15 entries from the bottom of the data and only return the data in these rows.  Does anyone know the best way of achieving this?  

Many thanks,

Daniel
0
Comment
Question by:Daniel131
  • 2
3 Comments
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 38802868
Probably ComboBox1.Text, not Value.

Dim lngLastRow as Long
Dim lngIndex As Long
Dim bFound As Boolean
' This assumes the data is in column 'I'
lngLastRow = Range("I65536").End(xlUp).Row

For lngIndex =  lngLastRow to lngLastRow - 15 Step -1
    ' '9' is column I
    If Instr(Cells(lngIndex, 9).Value, Combobox1.Text) > 0 Then 
        MsgBox lngIndex
        bFound = True
    End If
End If

If Not bFound Then
    MsgBox "No Parts Request Found"
End If

Open in new window

0
 

Author Closing Comment

by:Daniel131
ID: 38857256
Hi Thanks for the feeback!  Sorry it took so long to respond!  This works pretty good, however I think there is something else wrong with my code as when the loop is complete I am getting Error 1004 run time coming up.
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 38857273
You're welcome and I'm glad I was able to help.

Select the 'About Me' tab in my profile and you'll find links to some articles I've written that may interest you. In particular look at the one on debugging VB6. Most of it applies to Excel so using the techniques in the article you'll most likely be able to find the problem. If it does help, please consider marking it useful.

Marty - MVP 2009 to 2012
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

863 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

26 Experts available now in Live!

Get 1:1 Help Now