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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/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 VBA运行时错误424-对单元格()使用数组时出错_Excel_Vba - Fatal编程技术网

Excel VBA运行时错误424-对单元格()使用数组时出错

Excel VBA运行时错误424-对单元格()使用数组时出错,excel,vba,Excel,Vba,我有一个Excel电子表格,有多张表格,其中包含我们公司员工(mitarbeiter)提供的各种信息。现在,我创建了一个数组,其中包含它们的名称,这些名称与工作表名称相同。我想用它一张一张地循环浏览所有的表格,检索一些信息并打印在我准备的另一张表格上 最后,我尝试选择每个工作表,看看它是否选择了正确的工作表……结果是“运行时错误424需要对象” 这是你的括号,s/b工作表(mitarbeiter(i))。单元格(lastrow,lastrowcol)。选择这是你的括号,s/b工作表(mitarb

我有一个Excel电子表格,有多张表格,其中包含我们公司员工(mitarbeiter)提供的各种信息。现在,我创建了一个数组,其中包含它们的名称,这些名称与工作表名称相同。我想用它一张一张地循环浏览所有的表格,检索一些信息并打印在我准备的另一张表格上

最后,我尝试选择每个工作表,看看它是否选择了正确的工作表……结果是“运行时错误424需要对象”


这是你的括号,s/b
工作表(mitarbeiter(i))。单元格(lastrow,lastrowcol)。选择

这是你的括号,s/b
工作表(mitarbeiter(i))。单元格(lastrow,lastrowcol)。选择

好的,似乎已经工作了;为什么在“With”部分显示运行时错误9?(索引超出范围)–运行时错误9表示您正在调用不存在的东西。分割中可能没有足够的元素来填充数组,并且在最后调用一个空格。检查的一个好方法是使用F8单步执行并观察变量;为什么在“With”部分显示运行时错误9?(索引超出范围)–运行时错误9表示您正在调用不存在的东西。分割中可能没有足够的元素来填充数组,并且在最后调用一个空格。检查的一个好方法是使用F8单步执行并观察变量。
Sub Makro3()
Dim mitarbeiter As Variant
Dim lastrow As Long
Dim lastrowcol As Long

ReDim mitarbeiter(0 To 12) As Variant
mitarbeiter = Split(*censored*)
    
For i = LBound(mitarbeiter) To UBound(mitarbeiter)
   
With Sheets(mitarbeiter(i))
lastrow = .Cells(Rows.count, 13).End(xlUp).Row
lastrowcol = .Cells(Rows.count, 13).End(xlUp).Column
End With

ThisWorkbook.Worksheets(mitarbeiter(i).Cells(lastrow, lastrowcol)).Select 'crashes here
MsgBox mitarbeiter(i)

Next i
End Sub