Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Show months by English in combobox if the PC lang is differe

0

Hello ,

I would show  Months names by English language into  combobox1.

my problrm is regional setting  will be arabic language in windows system . so I search for way to avoid this problem without change regional setting to English.

I try to putting in array but doesn't work 

Private Sub UserForm_Activate()
Dim MonthName As Variant
MonthName = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
    Dim i As Integer
    For i = 1 To 12
        Me.ComboBox1.AddItem Format(MonthName, "mmm-yy")
        MonthName = DateAdd("m", 1, MonthName)
    Next
End Sub

any chance to achieve this without change setting regional in windows system,please?

Answer
Discuss

Answers

0
Selected Answer

Hi again Ali

I don't have much time but try the first attached file which has this code:

Option Base 1





Private Sub UserForm_Activate()

    Dim MonthName As Variant

    MonthName = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

    Dim i As Integer

    'For i = 1 To 1

        'Me.ComboBox1.AddItem Format(MonthName, "mmm-yy")

        'MonthName = DateAdd("m", 1, MonthName)

    ' add 12 English months from position in the array

    For i = 1 To 12

        Me.ComboBox1.AddItem MonthName(i)

    Next

End Sub

You should search the internet to see why I added "Option Base 1".

Hope this works well for you.

Revision #1 19 November 2024

The second attached file addresses the additional requirement from the user (see Discussion below) to add the last two digits of the current year to the Englisg three-letter month. It uses a new variable Yr  to capture the former. Changes to the code above are shoiwn in bold:

Private Sub UserForm_Activate()

    Dim MonthName As Variant

    Dim Yr As Long



    MonthName = Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")

    ' get last 2 digits of current year

    Yr = Right(Year(Date), 2)

    Dim i As Integer

    ' add 12 English months from position in the array

    For i = 1 To 12

        ' append current year to month

        Me.ComboBox1.AddItem MonthName(i) & "-" & Yr

    Next

End Sub

If this works for you, please remember to mark this Answer as Selected.

Discuss

Discussion

Thanks Jon .
it just show months without year!
should show like NOVE-24
Ali M (rep: 34) Nov 19, '24 at 9:06 am
Ali. I will revise my Answer when U get home but that aspect was NOT in your original question . In future please ensure that all requirements are in your question - we don't like re-making the solution.

I will assume you want the first 3 letters of each English month and the last 2 digits of the current year (e.g. 24 for current year 2024). Please say if that is not correct. 
John_Ru (rep: 6537) Nov 19, '24 at 11:32 am
I will assume you want the first 3 letters of each English month and the last 2 digits of the current year (e.g. 24 for current year 2024). Please say if that is not correct. 
yes this is what I look for it.
Ali M (rep: 34) Nov 19, '24 at 12:26 pm
Ali. I've addressed that point now- please see Revision #1 19 November 2024 and extra file in my Answer. 
John_Ru (rep: 6537) Nov 19, '24 at 1:50 pm
works as I want .
thank you.
Ali M (rep: 34) Nov 19, '24 at 2:17 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login