CCM
CCM

Reputation: 136

Excel Form Combobox value to cell

I have an Excel VBA Form and ComboBox that has the 12 months of the year. What I want it to do is when I select a month, it should also write that month value in a specific cell in the workbook as that cell value is linked throughout the workbook.

My issue here is that once loaded on opening the workbook, the values do not refresh and they do not copy from the ComboBox to the cell. How can I make this work ?

Private Sub Workbook_Open()

    With Form1
        .Show vbModeless 
        .ComboBox1.List = ThisWorkbook.Sheets("Liste").Range("D2:D13").Value 'month lists
    End With
    ThisWorkbook.Sheets("Sheet2").Range("B2").Value = Form1.ComboBox1.Value
End Sub

Upvotes: 2

Views: 18849

Answers (1)

Tim Schmidt
Tim Schmidt

Reputation: 1307

In Designmode you can double click the ComboBox to create the onChange method of your ComboBox.

This method gets called every time, the value of your ComboBox is changed.

In There you can put the code to write the value into the desired cell.

Private Sub ComboBox1_Change()
    ThisWorkbook.Worksheets("Sheet2").Range("B2").Value = Form1.ComboBox1.Value
End Sub

Upvotes: 4

Related Questions