Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.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/5/excel/25.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 Vba运行时错误1004_Vba_Excel - Fatal编程技术网

获取Excel Vba运行时错误1004

获取Excel Vba运行时错误1004,vba,excel,Vba,Excel,给予 运行时错误1004-“运行时错误“1004”: 应用程序定义或对象定义错误“ 似乎无法理解。正确调暗VAR,并使用application.inputbox获取更多选项 Private Sub CommandButton3_Click() Dim rownum, startcol, endcol, holder As Integer rownum = InputBox("Enter the row that swapping process going to happen")

给予

运行时错误1004-“运行时错误“1004”: 应用程序定义或对象定义错误“


似乎无法理解。

正确调暗VAR,并使用application.inputbox获取更多选项

Private Sub CommandButton3_Click()
    Dim rownum, startcol, endcol, holder As Integer
    rownum = InputBox("Enter the row that swapping process going to happen")
    startcol = InputBox("Enter the column of the cell you want to swap")
    endcol = InputBox("Enter the column of the cell that you wanted swap with")
    holder = Cells(rownum, startcol).Value
    Cells(rownum, startcol).Value = Cells(rownum, endcol).Value
    Cells(rownum, endcol).Value = holder
End Sub

类型:=1
告诉application.inputbox需要一个数字
type:=2
告诉application.inputbox需要一个字符串。

我看到的第一件事是需要清理DIM语句……只有
holder
被设置为整数,其他所有内容都是变量。其次,您可能不希望
rownum
是一个整数,因为在一个大的电子表格中,您可能很容易达到它的限制。您还需要将父工作表分配给每个范围对象:
工作表(“Sheet1”)。单元格(…
由于您没有正确地将变量设置为
Dim
,我猜问题是
rownum
等填充了
字符串
。修复这些变量,其余的就可以了。非常感谢您,这是一个简单的错误。我没有意识到它们是可变的。同样,根据您的上一个问题,我建议您提问“我该怎么做…”或“该怎么做…”的形式。在这里,“请帮助我”的形式通常被理解为“为我做我的工作”,即使这不是你想要的。
'using column numbers
Private Sub CommandButton3_Click()
    Dim rownum as long, startcol as long, endcol as long, holder As variant
    rownum = application.InputBox("Enter the row that swapping process going to happen", type:=1)
    startcol = application.InputBox("Enter the column number of the cell you want to swap", type:=1)
    endcol = application.InputBox("Enter the column numbedr of the cell that you wanted swap with", type:=1)
    holder = Cells(rownum, startcol).Value
    Cells(rownum, startcol).Value = Cells(rownum, endcol).Value
    Cells(rownum, endcol).Value = holder
End Sub

'using column letters
Private Sub CommandButton3_Click()
    Dim rownum as long, startcol as string, endcol as string, holder As variant
    rownum = application.InputBox("Enter the row that swapping process going to happen", type:=1)
    startcol = application.InputBox("Enter the column letter of the cell you want to swap", type:=2)
    endcol = application.InputBox("Enter the column letter of the cell that you wanted swap with", type:=2)
    holder = Cells(rownum, startcol).Value
    Cells(rownum, startcol).Value = Cells(rownum, endcol).Value
    Cells(rownum, endcol).Value = holder
End Sub