Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.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 基于inputbox中的输入值移动行_Excel_Vba - Fatal编程技术网

Excel 基于inputbox中的输入值移动行

Excel 基于inputbox中的输入值移动行,excel,vba,Excel,Vba,我需要一些帮助。我试图做的是根据inputbox中的用户输入移动一行。但是,我收到了一个无效的限定符错误。一定要帮助我,谢谢!突出显示的错误是lSource行 不完全确定你想要实现什么。但你可以试试看 With ActiveSheet 'Replace to suit - e.g. Sheets("Sheet1") Dim lSourceRow As Long Dim lDestRow As Long Dim zMsg As String lSourceRow

我需要一些帮助。我试图做的是根据inputbox中的用户输入移动一行。但是,我收到了一个无效的限定符错误。一定要帮助我,谢谢!突出显示的错误是lSource行


不完全确定你想要实现什么。但你可以试试看

With ActiveSheet 'Replace to suit - e.g. Sheets("Sheet1")
    Dim lSourceRow As Long
    Dim lDestRow As Long
    Dim zMsg As String

    lSourceRow = InputBox("Please Enter the row you want to move.")
    zMsg = "Move Row " & Format(lSourceRow) & " to what Row?" & _
          vbCrLf & "Enter 0 to Exit"

    lDestRow = InputBox(zMsg, "Move Entire Row", 0)

    If lDestRow <> 0 And lSourceRow <> 0 Then
        If lDestRow <> lSourceRow Then
            .Rows(lSourceRow).Cut
            .Rows(lDestRow + IIf(lDestRow = 1, 0, 1)).Insert xlDown
        Else
            MsgBox "Source Row and Destination Row" & vbCrLf & _
                "are the same -NO Action Taken-", _
                vbOKOnly + vbInformation, _
                "Invalid Row Move Request."
        End If
    End If
End With
这是最简单的形式。你想做的事情必须包括对输入的大量测试。 例如,如果它不是负数,不是字符串或小数,或者如果用户按Cancel或Close,则进行测试。 这只是你的开始。剩下的就交给你了。
这实际上是将行移动到目标行的上一个位置。HTH.

LSourceRow是一个字符串,不是一个范围,因此LSourceRow.Row将给出限定符错误。噢。所以我必须将lsourcerow声明为一个范围?这就是它的工作原理吗?抱歉,我对VBAAh不熟悉,因为您实际上没有向其传递范围对象。相反,您不应该使用.Row,因为我相信用户已经输入了行号,对吗?再说一次,.Row是一个范围对象属性。我希望它不会要求太多,但我试过了,它不起作用。你能帮我查一下密码吗?
With ActiveSheet 'Replace to suit - e.g. Sheets("Sheet1")
    Dim lSourceRow As Long
    Dim lDestRow As Long
    Dim zMsg As String

    lSourceRow = InputBox("Please Enter the row you want to move.")
    zMsg = "Move Row " & Format(lSourceRow) & " to what Row?" & _
          vbCrLf & "Enter 0 to Exit"

    lDestRow = InputBox(zMsg, "Move Entire Row", 0)

    If lDestRow <> 0 And lSourceRow <> 0 Then
        If lDestRow <> lSourceRow Then
            .Rows(lSourceRow).Cut
            .Rows(lDestRow + IIf(lDestRow = 1, 0, 1)).Insert xlDown
        Else
            MsgBox "Source Row and Destination Row" & vbCrLf & _
                "are the same -NO Action Taken-", _
                vbOKOnly + vbInformation, _
                "Invalid Row Move Request."
        End If
    End If
End With