Private Sub UserForm_Initialize()
'declare the variable
Dim Sh As Variant
Dim cc As Variant
cc = Sheet4.Range("C4").Value
'for each loop to add sheets based on permission rank
For Each Sh In ActiveWorkbook.Sheets
'add only permitted sheet(ranking 1 to 6) and exclude settings sheet
If Sh.Range("G1").Value >= cc And Sh.Name <> "settings" Then
'add sheets to the list box
Me.lstSheet.AddItem Sh.Name
End If
Next Sh
End Sub
尝试添加我。
这将刷新表单。
考虑将ListBox变量名称从1stSheet更改为sheet1ListBox,以使其更具描述性且更易于调试。