Solved

Search column for ComboBox Value in column and return Row text

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

830 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