Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Search column for ComboBox Value in column and return Row text

Posted on 2013-01-21
3
Medium Priority
?
291 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 49

Accepted Solution

by:
Martin Liss earned 1500 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 49

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

972 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