案例select语法创build一个循环我不想要的

我已经写了一个包括case select和一个msgbox的语法。 我希望语法find电子表格中的第一个活动单元格,并根据一些预定的问题和答案将其移动到A1或A2,但这些命令不能最佳地工作。 有人能帮我吗?

我希望消息框可以根据前面提供的答案直观地popup,但是消息框在循环中看起来似乎是一个错误。

我附上了下面的代码。

Public Sub SurvAnalysis() Dim InpSh As Worksheet Dim fCell As Range Dim msg1 As String, msg2 As String Dim Ans1 As Variant, Ans2 As Variant Set InpSh = ThisWorkbook.Worksheets("Input") msg1 = "Are these headers included in the Data, and is the data in the correct format? { Dob ∏ StartDate ∏ End Date }" Ans1 = MsgBox(msg1, vbYesNoCancel, " Data type") Select Case Ans1 Case vbYes On Error Resume Next Set fCell = InpSh.Cells.Find(What:="*", _ After:=InpSh.Cells(Rows.Count, Columns.Count), _ LookAt:=xlPart, _ LookIn:=xlFormulas, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) On Error GoTo 0 If fCell Is Nothing Then MsgBox "All cells are blank." Else fCell.CurrentRegion.Cut Destination:=InpSh.Range("A1") End If GoTo Quit: Case vbCancel MsgBox ("Get your data sorted out") GoTo Quit: Case vbNo GoTo Option2: End Select Quit: Option2: msg2 = "Are the data in the correct manner and do you wish for us to include the headers on your behalf?" Ans = MsgBox(msg2, vbYesNo, "Sort Data") Select Case Ans Case vbYes Set fCell = InpSh.Cells.Find(What:="*", _ After:=InpSh.Cells(Rows.Count, Columns.Count), _ LookAt:=xlPart, _ LookIn:=xlFormulas, _ SearchOrder:=xlByRows, _ SearchDirection:=xlNext, _ MatchCase:=False) If fCell Is Nothing Then MsgBox "All cells are blank." Else fCell.CurrentRegion.Cut Destination:=InpSh.Range("A2") InpSh.Range("A1").Value = " Dob" InpSh.Range("B1").Value = " StartDate" InpSh.Range("C1").Value = " End Date" End If Case vbNo MsgBox ("Get your data sorted out") GoTo Quit: End Select End Sub 

你的goto结束语句Quit:应该在最后。 在你的代码中,当它Quit:它将继续并处理它下面的所有代码行。 也正如一般的经验法则,这可能是意见,但通常你可以正确的代码,而不必使用任何goto语句。 他们造成更多的问题,而不是它的价值。 看看你是否可以写你的逻辑没有任何goto语句,你会终身。