获得1004错误

我试图写一个macros的水力逻辑模型值得我的成绩相当的%,我不断得到1004错误。 它集中在第一个If语句的第一行。

这是我正在使用的代码:

 Sub pheonix() ' ' pheonix Macro ' ' Keyboard Shortcut: Ctrl+u ' Dim WS As Worksheet Set WS = Sheets.Add Sheets.Add.Name = "RESULTS" Sheets("Case 2").Select Range("C1:R1").Select Selection.Copy Sheets("RESULTS").Select ActiveSheet.Paste Dim Row As Integer Dim Day As Integer Dim SurfaceInflow As Integer Dim GroundwaterOutflow As Integer Dim SurfaceOutflow As Integer Dim Stage As Integer Dim Evap As Integer Dim Precip As Integer Dim AreaL As Integer Dim ChangeStorage As Integer Dim Storage As Integer Dim InitialStorage As Integer Dim InitialStage As Integer Dim InitialArea As Integer Row = 2 'calulation for initial day 'InitialStage = "4" 'InitialArea = 11 * InitialStage ^ 0.5 'InitialStorage = (22 / 3) * (InitialStage ^ (3 / 2)) Set wksSource = ActiveWorkbook.Sheets("Case 2") Set wksDest = ActiveWorkbook.Sheets("RESULTS") For Day = 5 To 734 Sheets("RESULTS").Cells(Row, "A") = Sheets("Case 2").Cells(Row, "C") For i = 0 To 288 Sheets("Case 2").Select SurfaceInflow = ((0.2 * Cells(Day, "G")) * ((1 - 0.4) * (557 - Cells(Day, "J")))) + ((0.95 * Cells(Day, "G")) * (0.4 * (557 - Cells(Day, "J")))) If Cells(Stage, "H") >= 1.348 Then GroundwaterOutflow = (0.379 * Cells(Stage, "H") - 0.511) Else: GroundwaterOutflow = 0 End If If Cells(Stage, "H") > 2.9 Then SurfaceInflow = (33 * (Cells(Stage, "H") - 2.9) ^ (3 / 2)) Else: SurfaceInflow = 0 End If Precip = Cells(Precip, "S") Evap = Cells(Evap, "T") Area = (11 * Cells(Stage, "H") ^ 0.5) ChangeStorage = (Area * (Precip - Evap)) - GroundwaterOutflow + SurfaceInflow - SurfaceOutflow Storage = Storage + ChangeStorage Next i Sheets("RESULTS").Cells(Row, "B") = "X" Row = Row + 1 Next Day End Sub 

帮帮我? 我对任何编程都不是很熟悉,这是一个相当不幸的项目,由教授发起。

那是因为Stage的价值是0英寸

 If Cells(Stage, "H") >= 1.348 Then 

Excel行从1开始,可以在xl2003和之前达到最大值65536 ,或者在xl2007 +中达到1048576

另外build议将行variables声明为Long而不是Integer

你可能也想看到这个让你的代码更健壮。