S
S
Semyon892019-05-20 15:32:37
Visual Basic
Semyon89, 2019-05-20 15:32:37

VBA Excel 2016. How to change list by range in ComboBox using two OptionButton radio buttons?

Hello! I am new to VBA Excel. I'm trying to write 2 macros so that I can use two radio buttons to change the contents of the ComboBox on the sheet (not on the form). I tried to do this by clicking on the record macro button, in the first case I succeeded. I did it like this, clicked on the record, inserted a combo box from the developer panel, changed properties (inserted a range of cells and a link to the cell (for which I don’t know)). Clicked on stop recording. When assigning this macro to a RadioButton, everything worked, but when switching, another ComboBox was created each time.
In the second case, I just changed the value when writing a macro in my empty ComboBox properties. But macros obtained this way do not work - Run-time error '438' window pops up with debugging (Debug), end (End) and help (Help) suggestions. The Continue button is disabled. I press Debug, a window with a code appears, which shows that everything stops at the range .ListFillRange ="$T$1:$T$29". Please help how can I solve this issue?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene Kuznetsov, 2019-05-30
@Semyon89

You must use elements from the Form Controls group.
Then everything works. For example, I added a drop-down list and programmatically change its properties:

Sub Macro1()
'
' Macro1 Macro
'

'
    ActiveSheet.Shapes.Range(Array("Drop Down 1")).Select
    With Selection
        .ListFillRange = "$A$1:$A$3"
        .LinkedCell = ""
        .DropDownLines = 8
        .Display3DShading = False
    End With
End Sub

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question