add optionbutton(sheets) to code to populate data in listbox onuserform

abdelfattah

Well-known Member
Joined
May 3, 2019
Messages
1,429
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hello
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
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
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.

Forum statistics

Threads
1,214,921
Messages
6,122,280
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top