Solved

Search column for ComboBox Value in column and return Row text

Posted on 2013-01-21
3
277 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 45

Accepted Solution

by:
Martin Liss earned 500 total points
Comment Utility
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
Comment Utility
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 45

Expert Comment

by:Martin Liss
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
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…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

771 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

10 Experts available now in Live!

Get 1:1 Help Now