Hello, I have this code to search in several specific Excel sheets and show the results to the listbox. But it does not work when the number of columns exceeds 10. Is there a way to show 12 or 13 columns on the listbox? Here's a look at what I'm trying to find in the following code
VBA Code:
ivate Sub CommandButton1_Click()
Dim Found As Range
Dim Search As Variant
Dim firstaddress As String, msg As String
Me.ListBox1.Clear
Search = Me.TextBox1.Value
Do
If Me.TextBox1 = "" Then Exit Sub
Loop Until Search <> ""
Dim sh As Worksheet
For Each sh In Sheets(Array("Sheet1", "Sheet2", "Sheet5", "Sheet8"))
With sh.UsedRange
Set Found = sh.Range("a2:j1000").Find(Search, LookIn:=xlValues, lookat:=xlWhole)
If Not Found Is Nothing Then
firstaddress = Found.Address
Do
With ListBox1
.AddItem
.List(.ListCount - 1, 0) = sh.Cells(Found.Row, 1).Value
.List(.ListCount - 1, 1) = sh.Cells(Found.Row, 2).Value
.List(.ListCount - 1, 2) = sh.Cells(Found.Row, 3).Value
.List(.ListCount - 1, 3) = sh.Cells(Found.Row, 4).Value
.List(.ListCount - 1, 4) = sh.Cells(Found.Row, 5).Value
.List(.ListCount - 1, 5) = sh.Cells(Found.Row, 6).Value
.List(.ListCount - 1, 6) = sh.Cells(Found.Row, 7).Value
.List(.ListCount - 1, 7) = sh.Cells(Found.Row, 8).Value
.List(.ListCount - 1, 8) = sh.Cells(Found.Row, 9).Value
.List(.ListCount - 1, 9) = sh.Cells(Found.Row, 10).Value
' .List(.ListCount - 1, 10) = Found.Address
'.List(.ListCount - 1, 11) = Sh.Name
End With
Set Found = .FindNext(Found)
Loop While Not Found Is Nothing And Found.Address <> firstaddress
Else
MsgBox "Nothing found."
End If
End With
Set Found = Nothing
Next
End Sub