Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 运行时错误1004范围类的选择方法失败_Excel_Vba - Fatal编程技术网

Excel 运行时错误1004范围类的选择方法失败

Excel 运行时错误1004范围类的选择方法失败,excel,vba,Excel,Vba,我在运行代码时遇到1004错误: Public Sub UserSortInput() Dim userInput As String Dim promptMSG As String promptMSG = "Enter a numeric value to sort..." & vbCrLf & _ "1 --- Sort by Division" & vbCrLf &am

我在运行代码时遇到1004错误:

Public Sub UserSortInput()
    Dim userInput As String
    Dim promptMSG As String
        
    promptMSG = "Enter a numeric value to sort..." & vbCrLf & _
        "1 --- Sort by Division" & vbCrLf & _
        "2 --- Sort by Category" & vbCrLf & _
        "3 --- Sort by Total"
    
    userInput = InputBox(promptMSG)
    
    If userInput = "1" Then
        DivisionSort
    ElseIf userInput = "2" Then
        CategorySort
    ElseIf userInput = "3" Then
        TotalSort
    End If
    
End Sub
如果我调试,它会突出显示:

Public Sub UserSortInput()
    Dim userInput As String
    Dim promptMSG As String
        
    promptMSG = "Enter a numeric value to sort..." & vbCrLf & _
        "1 --- Sort by Division" & vbCrLf & _
        "2 --- Sort by Category" & vbCrLf & _
        "3 --- Sort by Total"
    
    userInput = InputBox(promptMSG)
    
    If userInput = "1" Then
        DivisionSort
    ElseIf userInput = "2" Then
        CategorySort
    ElseIf userInput = "3" Then
        TotalSort
    End If
    
End Sub
不熟悉VBA,所以不知道如何解决这个问题。我已经在信任中心启用了宏设置,但仍然不起作用


有人能帮忙吗?谢谢。

你确定这就是它强调的那一行吗?那行没有选择任何内容。是的。它也对其他用户输入执行相同的操作。谢谢。在错误消息的上下文中,这对我来说毫无意义。我建议你发布其余的代码(对于三个排序例程),因为不需要选择任何要排序的内容。Rory,我已经整理好了。谢谢这只是在VBA窗口中选择错误的问题。