Can you change this code or make it easy or suggest another code (1 Viewer)

zezo2021

Member
Local time
Today, 15:12
Joined
Mar 25, 2021
Messages
381
Hello friends;

I'm using this code to search in Excel Table and display the result in LISTBOX On USERFORM

but I think this code is complex

do you have another code?
Can you suggest an easier code?

Code:
Private Sub TextBox1_Change()
Dim Data, Arr, Crit As String
Crit = TextBox1
With Sheets("Database").ListObjects(1).Range
    Data = Filter(Evaluate("Transpose(If((" & .Columns(1).Address & "=""Name"")+(IsNumber(Search(""" & Crit & """," & .Columns(1).Address & "))),row(1:" & .Rows.Count & ")))"), False, 0)
    If UBound(Data) > -1 Then Arr = Application.Transpose(Application.Index(.Value, Data, Application.Evaluate("row(1:" & .Columns.Count & ")")))
    With Me.ListBox1
        .ColumnCount = 2
        .ColumnWidths = "270;60"
        .List = Arr
    End With
End With
End Sub
 

Isaac

Lifelong Learner
Local time
Today, 06:12
Joined
Mar 14, 2017
Messages
8,777
That's exactly a perfect example of what I mean when I occasionally go on my soapbox about readable code (and the triple-double-negative-boolean 1-line statements). i agree with you, that code stinks, although it looks fancy, it would be much easier to document, read, troubleshoot and maintain if the various dynamic aspects were chunked out. As is it will be virtually impossible to troubleshoot

Chunk it out so that each dynamic aspect of it (like columns(1).address, Search, etc) is a variable that is individually handled before hand, so that it is possible to see where what is happening
 

zezo2021

Member
Local time
Today, 15:12
Joined
Mar 25, 2021
Messages
381
I'm trying to find another solution asap
 

Users who are viewing this thread

Top Bottom