返回提示值

您好我工作的代码将返回每个案件的提示值的单元格(“A1”),但我似乎无法得到它的权利,例如,如果我select“情况1”,我想要的价值单元格“A1”为“1 – FCI18-0”,有没有办法做到这一点? 这里是我的代码如下:

Sub TestFunction() ans = InputBox("1 = FCI18-0" & vbCrLf & _ "2 = FCI18-1" & vbCrLf & _ "3 = FCI18-2" & vbCrLf & _ "4 = FCI18-3", "Model") Sheets("Sheet1").Range("a1").Value = InputBoxPrompt End Sub 

请帮忙

怎么样:

 Sub TestFunction() 'Declare variables Dim test(3) As String Dim i as long 'Set array with cases. Advantage of this set up is flexibility. In a later stage you can 'make a function that reads cases from a table in a (hidden) sheet into this array. 'This way you don't need to add new cases to your code, 'but you can add them in your excel sheet instead. test(0) = "FCI18-0" test(1) = "FCI18-1" test(2) = "FCI18-2" test(3) = "FCI18-3" 'read the input given by the user. You might want to add some checks here i = InputBox ("Which case?") Sheets("Sheet1").Range("a1").Value = test(i-1) End Sub 

使用Select Case

 Sub TestFunction() ans = InputBox("1 = FCI18-0" & vbCrLf & _ "2 = FCI18-1" & vbCrLf & _ "3 = FCI18-2" & vbCrLf & _ "4 = FCI18-3", "Model") Select Case ans Case 1: Sheets("Sheet1").Range("a1").Value = "1 = FCI18-0" Case 2: Sheets("Sheet1").Range("a1").Value = "2 = FCI18-1" Case 3: Sheets("Sheet1").Range("a1").Value = "3 = FCI18-2" Case 4: Sheets("Sheet1").Range("a1").Value = "4 = FCI18-3" End Select End Sub