ListView UserForm Control

pells

Active Member
Joined
Dec 5, 2008
Messages
361
I have set-up a listview control on a userform, which works well when searching through a named sheet. The results that appear in the listview are perfect.

The problem with my listview, is that is shows the row number of the record, which I am trying to figure out a way of removing, but not have any success.

My code is as follows:

Private Sub CommandButton1_Click()

Dim Cnt As Long
Dim Col As Variant
Dim FirstAddx As String
Dim FoundMatch As Range
Dim LastRow As Long
Dim R As Long
Dim StartRow As Long
Dim Wks As Worksheet

StartRow = 4

Set Wks = ActiveWorkbook.Sheets("Live Job List")

Col = ComboBox1.ListIndex + 1
If Col = 0 Then
MsgBox "Please choose a category."
Exit Sub
End If

If TextBox1.Text = "" Then
MsgBox "Please enter a search term."
TextBox1.SetFocus
Exit Sub
End If

LastRow = Wks.Cells(Rows.Count, Col).End(xlUp).Row
LastRow = IIf(LastRow < StartRow, StartRow, LastRow)

Set Rng = Wks.Range(Wks.Cells(1, Col), Wks.Cells(LastRow, Col))

Set FoundMatch = Rng.Find(What:=TextBox1.Text, _
After:=Rng.Cells(1, 1), _
LookAt:=xlPart, _
LookIn:=xlValues, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

If Not FoundMatch Is Nothing Then
FirstAddx = FoundMatch.Address
ListView1.ListItems.Clear

Do
Cnt = Cnt + 1
R = FoundMatch.Row
ListView1.ListItems.Add Index:=Cnt, Text:=R
For Col = 1 To 13
Set C = Wks.Cells(R, Col)
ListView1.ListItems(Cnt).ListSubItems.Add Index:=Col, Text:=C.Text
Next Col
Set FoundMatch = Rng.FindNext(FoundMatch)
Loop While FoundMatch.Address <> FirstAddx And Not FoundMatch Is Nothing
SearchRecords = Cnt
Else
ListView1.ListItems.Clear
SearchRecords = 0
MsgBox "No match found for " & TextBox1.Text
End If

End Sub


Private Sub UserForm_Activate()

Dim C As Long
Dim I As Long
Dim R As Long
Dim Wks As Worksheet

With ListView1
.Gridlines = True
.View = lvwReport
.HideSelection = False
.FullRowSelect = True
.HotTracking = True
.HoverSelection = False
.ColumnHeaders.Add Text:="Row", Width:=64
End With

Set Wks = ActiveWorkbook.Sheets("Live Job List")

For C = 1 To 3
ListView1.ColumnHeaders.Add Text:=Wks.Cells(4, C).Text
ComboBox1.AddItem Wks.Cells(4, C).Text
Next C

End Sub


Please can anyone see where I am going wrong?

Many thanks for taking the time to read my post and any help is much appreciated.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,215,584
Messages
6,125,673
Members
449,248
Latest member
wayneho98

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top