abdelfattah
Well-known Member
- Joined
- May 3, 2019
- Messages
- 1,429
- Office Version
- 2019
- 2010
- Platform
- Windows
Hello
I want reproducing this code .
I want adding about four optionbuttons based on four sheets and rename optionbutoon based on sheets names. so the optionbuttons names are matched sheets names .for instance if I have optionbutton 1 and its name is SH1 , then should search for sheet SH1 ,if it's matched then should populate data in listbox and should search the item in textbox within populated data in listbox based on selected optinbutton
thanks
I want reproducing this code .
VBA Code:
Dim arr() As Variant
Private Sub UserForm_Initialize()
Dim rng As Range
Dim r As Long, c As Long
Set rng = Worksheets("sheet1").Range("A2:F15")
ReDim arr(1 To rng.Rows.Count, 1 To rng.Columns.Count)
For r = 1 To UBound(arr, 1)
For c = 1 To UBound(arr, 2)
arr(r, c) = rng.Cells(r, c).Text
Next c
Next r
With Me.ListBox1
.ColumnCount = UBound(arr, 2)
.ColumnWidths = "80,120,80,80,80,80"
.List = arr
End With
End Sub
Private Sub textbox1_Change()
Dim rw()
For i = 1 To UBound(arr)
If LCase(arr(i, 2)) Like "*" & LCase(TextBox1.Value) & "*" Then
ReDim Preserve rw(p)
rw(p) = Application.Index(arr, i, 0)
p = p + 1
End If
Next
If p = 0 Then MsgBox "NO MATCH": Exit Sub
With ListBox1
If p > 1 Then
.List = Application.Transpose(Application.Transpose(rw))
Else
.Column = Application.Transpose(rw)
End If
End With
End Sub
thanks