【发布时间】:2013-02-18 19:17:36
【问题描述】:
我知道可以使用If 语句,但出于好奇,如标题中所述,是否可以使用SELECT 语句来执行以下BOLDED 的操作?我已将我的整个Sub 提交如下,以便更好地理解:
子 addNewCust_Click()
Dim response As String
response = Application.InputBox(prompt:="", Title:="New customer name", Type:=2)
Select Case response
Case False
Exit Sub
'Check if response is not an empty value AND record found in "CustomerList"
案例是 "" & WorksheetFunction.CountIf(Worksheets("CustomerList").Range("B:B"), response) > 0
MsgBox "'" & response & "' already exists on this sheet."
Call addNewCust_Click
'Check if response is not an empty value and record is not found in "Customerlist"
案例是 "" & WorksheetFunction.CountIf(Worksheets("CustomerList").Range("B:B"), response)
Sheets("CustomerList").Range("B1048576").End(xlUp).Offset(1, 0).Value = response
MsgBox "'" & response & "' successfully entered!"**
Case Else
MsgBox "Field is empty!"
Call addNewCust_Click
End Select
End Sub
【问题讨论】: