简体   繁体   English

如何将此下拉列表合并到我的程序代码 VBA 中

[英]How to incorporate this drop-down list into my program code VBA

I have the following drop-down/combo box list that has two options, namely Internal and External .我有以下下拉/组合框列表,其中有两个选项,即InternalExternal My drop-down list looks like this:我的下拉列表如下所示: 在此处输入图片说明

And then I have a macro that runs through the following button:然后我有一个通过以下按钮运行的宏: 在此处输入图片说明

My question does not revolve around the actual content of the code but rather the structure of the code to include the drop-down list, so I have simplified it a lot for the sake of getting to the point.我的问题不是围绕代码的实际内容,而是围绕包含下拉列表的代码结构,所以为了切入正题,我对其进行了大量简化。 My (simplified) code initially made a rudimentary calculation.我的(简化)代码最初进行了初步计算。

Sub InsertEquitiesBonds(Dim x as Double, Dim y as Double)
Dim ws as Worksheet
Set ws = Worksheets("PnL")
ws.Range("C4").Value = x + y
End Sub

I would like to create a decision logic in this code after clicking populate , so like:单击populate ,我想在此代码中创建决策逻辑,例如:

If DropDown6_Change.Value = "Internal" Then
ws.Range("C4").Value = x + y 
Else 
ws.Range("C4").Value = x - y
End If

What do I need to use for the above code to be realized?我需要用什么来实现上面的代码?

Almost there.差不多好了。

Sub DropDown1_Change()
    Dim ws As Worksheet
    Set ws = Sheets("Sheet1")
    x = 10
    y = 5
    With ThisWorkbook.Sheets("Sheet1").Shapes("Drop Down 1").ControlFormat
        Select Case .List(.Value)
        Case "Internal": ws.Range("C4").Value = x + y
        Case "External": ws.Range("C4").Value = x - y
        End Select
    End With
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM