vba运行时错误9下标越界
Sub moyenne()Dim moyenne As DoubleDim i, g As IntegerDim A As Integerg = 3Doi = 4A = 0somcoef = 0 Do note = Worksheets("feuil1").Range(Cells(g, i), Cells(g, i)).Value coef = Worksheets("feuil1").Range(Cells(g,i), Cells(2, i)).Value If note <> "" Then A = note * coef + A somcoef = coef + somcoef End If i = i + 1 Loop until Cells(g, i).Value <> "" If somcoef <> 0 Then moyenne = A / somcoef Worksheets("feuil1").Range(Cells(g, 2), Cells(g, 2)).Value = moyenne End If g = g + 1 Loop until Cells(g, 4).Value <> ""End Sub 运行时提示错误9 下标越界请大家帮忙改正一下谢谢 “错误9 下标越界”错误发生在代码行“note = Worksheets("feuil1").Range(Cells(g, i), Cells(g, i)).Value”,这里的引用“Worksheets("feuil1")”是最易发生错误的,引用的表名“feuil1”必须是“name”属性值而不是“名称”属性值,也就是应该是编辑器的对象浏览器里“Microsoft excel”对象的括号里的值,同时也是表格界面里的工作表标签的名称。
顺便说一下,后面还有一些其他错误(比如“Cells(g, i).Value <> ""”这个引用错误,会导致运行时错误1004“应用程序定义或对象定义错误”)。
热门标签: