Sorry if I have broken the rules. What I am trying to do is step trough all the cells in column A and find all the cell that contain the same thing as entered in textbox1. The above codes works in as far that it only finds the first match. Any ideas

This post has been edited by Atli: 29 March 2013 - 02:36 PM
Reason for edit:: Use [code] tags when posting code.

Replies To: Search an excel file for string entered in textbox

Re: Search an excel file for string entered in textbox

Posted 29 March 2013 - 02:51 PM

I assume you keyed this in Excel VBA?

Yes, it will only check the first item as that is what you have told it to do..!

You could study the following code:

Dim aCell As Range
ListBox1.ColumnCount = 1
For Each aCell In Range("A:A")
'don't want to check EVERY cell in the column..
If IsEmpty(aCell.Value) Or aCell.Value = "" Then
Exit For
ElseIf aCell.Row > 1000 Then
Exit For
End If
If aCell.Value = x Then
ListBox1.AddItem acell.Offset(0, 1).Value
End If
Next aCell

Re: Search an excel file for string entered in textbox

Posted 31 March 2013 - 04:29 AM

Thanks andrewsw
I tried that code you gave me and it works perfect. Does not write any thing to the listbox I'll see if i did some thing stupid. Just in relation to the code I posted first I got it working by putting the loop command at the bottom, but this gives me a problem that it does not stop when it meets at blank cell. I tried putting in the code line[If activecell.value="" then
exit if.] Any ides where I went wrong