簡體   English   中英

錯誤 91 VBA Excel

[英]Error 91 VBA Excel

在 VBA 中執行代碼時出現錯誤 91

有我的代碼

Sub Traingulation()    
 Dim table As Range
 Dim tableRows As Integer
 Dim tableCols As Integer
 Dim ws As Worksheet   

 Set table = ws.Cells
 tableRows = ws.UsedRange.Rows.Count
 tableCols = ws.UsedRange.Columns.Count

 Dim x1 As Double
 Dim x2 As Double
 Dim x3 As Double
 Dim y1 As Double
 Dim y2 As Double
 Dim y3 As Double   

 Dim r1 As Double
 Dim r2 As Double
 Dim r3 As Double    

 Dim phase1 As Double
 Dim phase2 As Double
 Dim phase3 As Double    
 Dim frequence1 As Double
 Dim frequence2 As Double
 Dim frequence3 As Double   
 Dim A As Double
 Dim B As Double
 Dim C As Double
 Dim D As Double
 Dim E As Double
 Dim F As Double   
 Dim Xu As Double
 Dim Yu As Double

 x1 = Range("L5").Value
 x2 = Range("L6").Value
 x3 = Range("L7").Value
 y1 = Range("M5").Value
 y2 = Range("M6").Value
 y3 = Range("M7").Value

 For i = 1 To table1Rows
   For j = 1 To table1Cols
     If table(i, 5).Value = 1 Then
       phase1 = table(i, 2).Value & frequence1 = table(i, 3).Value
     End If
   Next

   If table(i, 5).Value = 2 Then  
     phase1 = table(i, 2).Value & frequence1 = table(i, 3).Value
   End If
 Next

 If table(i, 5).Value = 3 Then
   phase1 = table(i, 2).Value & frequence1 = table(i, 3).Value
 End If

 r1 = -(3 * 10 ^ 8 * phase1) / 4 * 3.14 * frequence1    
 r2 = -(3 * 10 ^ 8 * phase2) / 4 * 3.14 * frequence2
 r3 = -(3 * 10 ^ 8 * phase3) / 4 * 3.14 * frequence3

 A = x3 - x1
 B = y3 - y1
 C = x3 - x2
 D = y3 - y2
 E = ((r1) ^ 2 - (r3) ^ 2) - ((x1) ^ 2 - (x3) ^ 2) - ((y1) ^ 2 - (y3) ^ 2)
 F = ((r2) ^ 2 - (r3) ^ 2) - ((x2) ^ 2 - (x3) ^ 2) - ((y2) ^ 2 - (y3) ^ 2)

 Xu = 0.5 * ((F * B) - (D * E)) / ((C * D) - (A * D))
 Yu = (0.5 * E / B) - (A * ((F * B) - (D * E))) / (B * ((C * B) - (A * B))) 

 MsgBox "Triangulation : Xu =  " & Xu & ",  et Yu =  : " & Yu & " "
End Sub

在此處定義您的工作表:

 Set table = ActiveSheet.Cells
 tableRows = ActiveSheet.UsedRange.Rows.Count
 tableCols = ActiveSheet.UsedRange.Columns.Count

暫無
暫無

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

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