簡體   English   中英

當我嘗試運行此 VBA 代碼時出現錯誤號 5

[英]Error number 5 when I try to run this VBA code

Sub SOLAR()
'
' SOLAR Macro
' SOLAR CALCULATION
'

'
    Application.Goto Reference:="SOLAR"
    
    Dim c_size As Single
    Dim current As Integer
    Dim cable_length As Integer
    Dim voltage_drop_rate As Integer
    Dim c_capacity As Integer
    Dim v_drop As Integer
    Dim load As Integer
    Dim energy_units As Integer
    Dim panel_number As Single
    Dim energy As Integer
    Dim found As Integer
    Dim no_panels_req As Single
    Dim no_panels As Integer
    Dim panels As Integer
      
   'pick details from Panel size and calculate panel size
        
             If (load <> Empty) And (energy <> Empty) Then
                found = 0
                
   
                energy_units = Worksheets("SOLAR").Range("LOAD").Cells("I33").Value
                    load = Worksheets("SOLAR").Range("LOAD").Cells("I34").Value
                       PSH = Worksheets("SOLAR").Range("REGION").Cells("E24").Value
   
                                    no_panels_req = ((energy_units * 1.2) / PSH) * 1000
                   
                   no_panels = no_panels_req
                   
   End If
                panels = no_panels
                
End Sub

根據我上面的評論,您報告的錯誤 5 的原因是濫用 Cells 屬性。 按照建議,查看幫助,您將了解:
o Cells 的語法是Cells(row, column) ,而不是您在代碼中使用的Cells(address)
o rowcolumn可以是數值、產生數值的方程或包含數值的變量。

此外(幫助中未涵蓋):
o column可以是字符串列引用,例如: Cells(1, "A")
o excel 自動將列引用轉換為列號
o 因此Cells(1, "A")Cells(1, 1)

這是引發錯誤 5 的Cells(address)語法
糾正這一點,您將解決錯誤 5 問題。

暫無
暫無

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

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