[英]Assign macro in drop down list and run with button
我創建了幾個生成ID
宏。 現在,我需要將它們放在下拉列表中進行選擇。
我的想法是,我將在按鈕上方插入一個按鈕(我們稱其為GENERATE
)和一個下拉列表單元格。 隨着下拉列表中值的更改, GENERATE
按鈕將相應地生成其他公式的ID
。 這是我的代碼,盡管我不確定它們是否正確。
Sub GenerateID()
Dim macroName As String
macroName = Range("A4").Value
If macroName = NRIC Then
Application.Run (GenerateNRICFIN)
ElseIf macroName = FIN Then
Application.Run (GenerateFIN)
ElseIf macroName = RB Then
Application.Run (GenerateRB)
ElseIf macroName = RB2 Then
Application.Run (GenerateRB2)
ElseIf macroName = RB3 Then
Application.Run (GenerateRB3)
ElseIf macroName = RB4 Then
Application.Run (GenerateRB4)
ElseIf macroName = RB5 Then
Application.Run (GenerateRB5)
ElseIf macroName = RC Then
Application.Run (GenerateRC)
ElseIf macroName = RC2 Then
Application.Run (GenerateRC2)
ElseIf macroName = RC3 Then
Application.Run (GenerateRC3)
ElseIf macroName = RC4 Then
Application.Run (GenerateRC4)
ElseIf macroName = RC5 Then
Application.Run (GenerateRC5)
ElseIf macroName = RC6 Then
Application.Run (GenerateRC6)
End If
End Sub
用這個:
Sub GenerateID()
Dim macroName As String
'macroName = Range("A4").Value
macroName = ThisWorkbook.Sheets("Sheet1").Range("A4").Value
IF (macroName = "NRIC") then macroName = "NRICFIN"
Application.Run "Generate" & macroName
END Sub
而不是所有的if語句。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.