same codes for same command buttons procedures

Amin Kaveh

New Member
Joined
Jan 17, 2019
Messages
18
Hi
I am designing a calendar with 365 command button as 365 days, and all buttons has same codes in spite of indexes.
Is there any way to have one procedure instead of 365. for example my first day on seventh month procedure is here:

Private Sub day_7_1_Click()
For i = 1 To Sheets.Count
If Worksheets(i).Name = Right(Daily_Report.main_year.Text, 2) & ".07.01" Then
Call Daily_Report.CommandButton_edit_Click
End If
Next i
Daily_Report.Text1_date = Daily_Report.main_year.Value
Daily_Report.Text2_date = "07"
Daily_Report.Text3_date = "01"
End Sub

Thanking you in advance
 
For clsMonthCommandButton, try...

Code:
Option Explicit

Public WithEvents MonthCommandButton As MSForms.CommandButton


Private Sub MonthCommandButton_Click()


    Dim sMonth As String
    Dim i As Long
    
    sMonth = Split(MonthCommandButton.Name, "_")(1)
    
    For i = 1 To 12
        With UserForm1
            .Controls("Frame_" & i).Visible = IIf(i = CLng(sMonth), True, False)
            .Controls("month_" & i).BackColor = IIf(i = CLng(sMonth), &H8080FF, &H8000000F)
        End With
    Next i


End Sub

Change the userform name, accordingly.

Hope this helps!
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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