【发布时间】:2015-01-07 13:20:27
【问题描述】:
我需要一些帮助。我要做的是根据输入框中的用户输入移动一行。但是我收到了一个无效的限定符错误。帮帮我,谢谢!突出显示的错误是lSource 行。
Sub MoveRow()
Dim lDestRow As Long
Dim lSourceRow As String
Dim zMsg As String
lSourceRow = InputBox("Please Enter the row you want to move")
zMsg = "Move Row " & Format(lSourceRow.Row) & " to Row?" & _
vbCrLf & "Enter 0 to Exit"
lDestRow = InputBox(zMsg, "Move Entire Row", 0)
If lDestRow <> 0 And lDestRow <> lSourceRow Then
ActiveCell.EntireRow.Select
Selection.Cut
Rows(lDestRow).Select
Selection.Insert Shift:=xlDown
Else
If lDestRow <> 0 Then
MsgBox "Source Row and Destination Row" & vbCrLf & _
"are the same -NO Action Taken-", _
vbOKOnly + vbInformation, _
"Invalid Row Move Request"
End If
End If
End Sub
【问题讨论】:
-
LSourceRow是一个字符串而不是一个范围,所以LSourceRow.Row会给出限定符错误。 -
哦。所以我必须将 lsourcerow 声明为一个范围?它是这样工作的吗?抱歉,我是 VBA 新手
-
啊,不,因为您实际上并没有将范围对象传递给它。相反,您不应该使用
.Row,因为我相信用户已经输入了行号,对吗?同样,.Row是 Range 对象属性。 -
我希望它没有要求太多,但我试过了,但没有用。你能帮我写代码吗?