Excel 2002: Need help with Listview

B

BVHis

Okay Excel gurus.... I'm gonna cry "uncle" and admit that I've hit
wall with this one.

What I'm trying to do is create my own kind of search program. I'v
got a UserForm with a ListView control on it. The ListView control ha
4 columns. The code below (some of which has come from this forum
prompts the user for a word to find. What it's *supposed* to do i
this: For every instince of the word that is found, add an entry int
the ListView with the following information for each column:
1) How many have been found (if there are three, there should be thre
entries; 1, 2 & 3)
2) The Sheet name
3) The cell address
4) The text that was found

And here's the code that I've got so far.
Any help will be greatly appreciated!

Thanks in advance!

Option Explicit


Private Sub UserForm_Initialize()
Dim oSheet As Object
Dim Firstcell As Range
Dim NextCell As Range
Dim WhatToFind As Variant
Dim blnFound As Boolean
Dim strSearchText As String
Dim i As Integer
i = 1
Dim li As ListItem
Dim list As Variant

lvwSearchResults.ListItems.Clear
Set li = lvwSearchResults.ListItems.Add()

WhatToFind = Application.InputBox("What are you looking for ?"
"Search", , 100, 100, , , 2)
If WhatToFind <> "" And Not WhatToFind = False Then
For Each oSheet In ActiveWorkbook.Worksheets
oSheet.Activate
oSheet.[a1].Activate
Set Firstcell = Cells.Find(What:=WhatToFind
LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows
SearchDirection:=xlNext, MatchCase:=False)
If Not Firstcell Is Nothing Then
Firstcell.Activate
strSearchText = strSearchText & vbCr & WhatToFind &
in " & oSheet.Name & "!" & Firstcell.Address
li.Text = "~"
li.ListSubItems.Add , , oSheet.Name
li.ListSubItems.Add , , Firstcell.Address
li.ListSubItems.Add , , WhatToFind
On Error Resume Next
While (Not NextCell Is Nothing) And (No
NextCell.Address = Firstcell.Address)
Set NextCell = Cells.FindNext(After:=ActiveCell)
If Not NextCell.Address = Firstcell.Address Then
NextCell.Activate
strSearchText = strSearchText & vbCr
WhatToFind & " in " & oSheet.Name & "!" & NextCell.Address
li.Text = "~"
li.ListSubItems.Add , , oSheet.Name
li.ListSubItems.Add , , Firstcell.Address
li.ListSubItems.Add , , WhatToFind
End If
i = i + 1
Wend
End If
Set NextCell = Nothing
Set Firstcell = Nothing
i = i + 1
Next oSheet
End If
' MsgBox strSearchText
End Su
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top