PFA workbook.
Please help me to set the ListView on userform as per mention in workbook
Printable View
PFA workbook.
Please help me to set the ListView on userform as per mention in workbook
Hi
Replace the userform module code with the following.
Code:Private Sub CommandButton1_Click()
'SEARCH
Dim Cnt As Long
Dim FirstAddx As String
Dim FoundMatch As Range
Dim LastRow As Long
Dim R As Long
Dim StartRow As Long
Dim Wks As Worksheet
Dim Rng As Range
Dim lstItem As ListItem
StartRow = 2
Set Wks = Sheets(1)
If TextBox1.Text = "" Then
MsgBox "Please enter a search term."
TextBox1.SetFocus
Exit Sub
End If
Set Rng = Wks.Range("A2:g" & Wks.Range("a" & Wks.Rows.Count).End(3).Row)
Set FoundMatch = Rng.Find(What:=TextBox1.Text, LookAt:=xlPart, MatchCase:=False)
If Not FoundMatch Is Nothing Then
FirstAddx = FoundMatch.Address
ListView1.ListItems.Clear
For R = 1 To Rng.Rows.Count
ListView1.ListItems.Add R
Next
Do
Cnt = FoundMatch.Column
R = FoundMatch.Row
If Cnt = 1 Then
ListView1.ListItems(R - 1).Text = FoundMatch.Text
Else
Set lstItem = ListView1.ListItems(R - 1)
lstItem.SubItems(Cnt - 1) = FoundMatch.Text
End If
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
End With
Set Wks = Sheets(1)
For C = 1 To 7
ListView1.ColumnHeaders.Add Text:=Wks.Cells(1, C).Text
Next C
End Sub
thank u so much Admin for u r help and time..! :cheerclink:
Thanks for the feedback :cheers: