簡體   English   中英

運行時錯誤“1004”-object“_Global”的方法“范圍”失敗

[英]Run-time error '1004' - Method 'Range' of object '_Global' failed

在代碼中:

Sub sync()

          Dim Dindex As Long 'the index of the D value we are on currently.
          Dim Aindex As Long 'the index of the A value we are on currently
          Dim Gindex As Long 'the index of the A value we are on currently
          Dim Dvalue As Double 'the cell in D value we want to normalize by -time
          Dim Avalue As Double 'the A cell value - time
          Dim Bvalue As Double
          Dim Hvalue As Double
          Dim Gvalue As Double 'the G cell value - time

          Dindex = 3
          Aindex = 3
          Gindex = 3

          Dvalue = Cells(Dindex, 4).Value 'start value

          Avalue = Cells(Aindex, 1).Value 'start value

          Gvalue = Cells(Gindex, 7).Value

          Do While Dvalue <> 0
                    Do While Avalue < Dvalue
                              Aindex = Aindex + 1
                              Avalue = Range("A" & CStr(Aindex)).Value
                    Loop
                    Do While Gvalue < Dvalue
                              Gindex = Gindex + 1
                              Gvalue = Range("G" & CStr(Gindex)).Value
                    Loop
                    Bvalue = Cells(Aindex, 2)
                    If Avalue <> Dvalue Then
                              Aindex = Aindex - 1
                              Bvalue = (Bvalue + Range("A" & CStr(Aindex)).Value) / 2
                    End If
                    Hvalue = Cells(Gindex, 8).Value
                    If Gvalue <> Dvalue Then
                              Gindex = Gindex - 1
                              Hvalue = (Hvalue + Range("G" & CStr(Gindex)).Value) / 2
                    End If
                    Cells(Dindex, 10).Value = Dvalue
                    Cells(Dindex, 11).Value = Bvalue
                    Cells(Dindex, 12).Value = Hvalue
                    Dindex = Dindex + 1
                    Dvalue = Cells(Dindex, 4).Value
          Loop

End Sub

在行中時出現錯誤:Avalue = Range("A" & CStr(Aindex)).Value 當 Aindex 值達到 1048577 時。我懷疑問題出在我試圖到達如此大的單元格時,代碼的目標是將 3 個不同的時間系統值放在同一個時間系統上,所以我需要超越那個單元格。

感謝 BigBen,我發現 excel 列的最大值為 1048576,並成功修復了我的代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM