hi all, i'm using the following code to find a particular name in my workbook, and then return particular cell value from the sheets on which it is found.
How do i get the resulting array to populate a listbox on a userform? also, if the result is zero, how do i have "No Bookings" show up in the listbox?
Code:
Public Sub search() Dim ws As Worksheet
Dim rngFound As Range
Dim strFirst As String
Dim strSearch As String
Dim strWSname As String
Dim Excludedsheets As Variant, GetSearchArray As Variant
Dim x As Variant
Dim l As Long
l = 1
strSearch = "bugger"
For Each ws In ActiveWorkbook.Sheets
Excludedsheets = Array("Homepage", " ", " ", "Trips", "Data", "First", "Last", "Members")
x = Application.Match(ws.Name, Excludedsheets, 0)
If IsError(x) Then
l = l + 1
Set rngFound = ws.Range("C:C").Find(strSearch, ws.Range("C4"), xlValues, xlWhole, xlByColumns)
If Not rngFound Is Nothing Then
strWSname = ws.Range("D2") & " " & ws.Range("g2")
If InStr(1, ws.Name, " ", vbTextCompare) > 0 Then strWSname = strWSname
strFirst = rngFound.Address
Do
GetSearchArray = GetSearchArray & "|" & strWSname
Set rngFound = ws.UsedRange.Find(strSearch, rngFound, xlValues, xlPart)
Loop While rngFound.Address <> strFirst
End If
End If
Next ws
If Len(GetSearchArray) > 0 Then GetSearchArray = Mid(GetSearchArray, 2)
End Sub
How do i get the resulting array to populate a listbox on a userform? also, if the result is zero, how do i have "No Bookings" show up in the listbox?