0

recently i came across a userfrom which have list box which shows the sheets name in first column and there property like are they visible or hidden in second columns. but when i tried to access the codes its lock i googled and did every thing to understand how it is done but i didnt found it hope i get my answer here below is mycode which i did i am noob please help me

my code:-

Private Sub UserForm_Initialize()

Dim ws As Worksheet


ListBox1.ColumnCount = 2
For Each ws In ThisWorkbook.Worksheets

    Me.ListBox1.AddItem ws.Name

Next ws

End Sub
1
  • Do the listbox properties reference a cell range in the rowsource property? You could work with that property to change the cell range and add a new item within the new range. Commented Feb 9, 2022 at 17:35

2 Answers 2

1
Private Sub UserForm_Initialize()

    Dim ws As Worksheet, n As Long, arText
    arText = Array("xlSheetVisible", "xlSheetHidden", "", "xlSheetVeryHidden")
    
    ListBox1.ColumnCount = 2
    For Each ws In ThisWorkbook.Worksheets
        Me.ListBox1.AddItem ws.Name
        Me.ListBox1.List(n, 1) = arText(ws.Visible + 1)
        n = n + 1
    Next ws

End Sub
Sign up to request clarification or add additional context in comments.

2 Comments

thank you so much its working and i want to ask 1 more help how can i add headers like the column which shows the sheet name as "Worksheet Names" and for another it will be "Sheet Type" sorry for bothering you but it will help me thank you in advance...
@kunal unfortunately its not that easy stackoverflow.com/questions/657498/….
0

There are several possibilities. One of them is:

Sub ListBoxMitArrayAusTabelleFuellen()
 Dim VarDat As Variant
 Dim lngRowMax As Long

 With Tabelle1

  lngRowMax = .Range("A" & .Rows.Count).End(xlUp).Row
  VarDat = .Range("A2:B" & lngRowMax ).Value

  .ListBox1.ColumnCount = UBound(VarDat, 2)
  .ListBox1.Clear
  .ListBox1.List = VarDat

 End With

End Sub

BG Bernd

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.