Shorten code

  • Good Morning: Can the following code be shortened? I have enclosed the beginning of the code which continues on to Week 34.


    Thanks
    abbeville

  • Re: Shorten code


    Different approach.

  • Re: Shorten code


    What about:


    [vba]
    ComboBox1.AddItem 0
    For x = 1 To 34 Step 1
    ComboBox1.AddItem Format(x, "0")
    Next x
    returnvalue = ComboBox1
    If returnvalue = 0 Then
    Sheet79.Select
    Else
    Sheets("Week " & returnvalue).Visible = True
    End If
    [/vba]


    TJ

  • Re: Shorten code


    or to mod Roy's post:


    [vba]
    Private Sub UserForm_Initialize()
    Dim wSht As Worksheet

    With Me.ComboBox1
    For Each wSht In ActiveWorkbook.Worksheets
    If wSht.Name Like "Week*" Then
    .AddItem wSht.Name
    End If
    Next wSht
    End With

    End Sub
    [/vba]


    TJ

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!