Solved

Search column for ComboBox Value in column and return Row text

Posted on 2013-01-21
3
285 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
[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
3 Comments
 
LVL 47

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 47

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

710 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