View Single Post
 
Old 04-23-2018, 09:27 AM
NoSparks NoSparks is offline Windows 7 64bit Office 2010 64bit
Excel Hobbyist
 
Join Date: Nov 2013
Location: British Columbia, Canada
Posts: 842
NoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of lightNoSparks is a glorious beacon of light
Default

to get started... try this for your form Initialization
Code:
Private Sub UserForm_Initialize()

Dim Ws As Worksheet, lr As Long, i As Long, j As Long
Dim dic As Object, arr As Variant
Dim ctrl As Control, thisFrame As Control

Set dic = CreateObject("Scripting.Dictionary")

For Each Ws In ActiveWorkbook.Worksheets
    Select Case UCase(Ws.Name)
    Case "FY2019", "FY2020", "FY2021", "FY2022", "FY2023"
        With Ws
            lr = .Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
            'for combo drop down
            arr = .Range("B2:B" & lr)
            For i = 1 To UBound(arr, 1)
                If arr(i, 1) <> "" And InStr(arr(i, 1), "Total") = 0 And InStr(arr(i, 1), "TOTAL") = 0 Then
                    dic(arr(i, 1)) = 1
                End If
            Next i
            'for labels
            j = 3
            Set thisFrame = Controls("frame" & Ws.Name)
            For Each ctrl In thisFrame.Controls
                If TypeOf ctrl Is MSForms.Label Then
                    ctrl.Caption = Format(.Cells(1, j).Value, "mmm-yy")
                    j = j + 1
                End If
            Next ctrl
        End With
    End Select
Next Ws
            
'populate combobox
cboFYList.List = Application.Transpose(dic.keys)

End Sub
Reply With Quote