我試圖讓我的Sub基於MsgBoxReults重新啓動。我的代碼不包含任何錯誤,但不會根據用戶的選擇重新啓動(希望在另一個IF中有IF語句不是問題)Excel VBA基於VbMsgBoxResult重新啓動相同的子程序本身
請協助。
Sub ContinueWeatherList()
Dim Weather As String
'Assigning a Message Box result as a Variable for Yes/No
Dim MoreWeather As VbMsgBoxResult
Weather = InputBox("Type in the weather for " & Range("C1").End(xlDown) + 1)
If Weather = "" Then
MsgBox ("No data entered. Your response has not been recorded"), vbExclamation
Else
Range("C1").End(xlDown).Offset(1, 0).Value = Range("C1").End(xlDown) + 1
Range("A1").End(xlDown).Offset(1, 0).Value = Range("A1").End(xlDown) + 1
Range("B1").End(xlDown).Offset(1, 0).Value = Weather
Columns("A:C").EntireColumn.AutoFit
MsgBox "Thank you for entering your data " & vbNewLine & "Would you like to enter another?", vbYesNo
'Using IF statement to decide what happens for each condition
If MoreWeather = vbYes Then
''Call' command won't reinitiate Sub/*NEED TO FIX*
Call ContinueWeatherList
Else
MsgBox "Thank you for you input.", vbInformation
End If
End If
結束子
@J VBA,擁有和中頻IF ISN內這個問題(取決於你試圖達到的邏輯)。看到我的回答如下 –