- 打開VBE(Visual Basic編輯器)ALT + F11
- 右鍵單擊Project Explorer中和插入一個
Module
- 粘貼下面的代碼
UDF f unctions
Function E()
Dim D As Range, F As Range
Set D = ActiveCell.Offset(0, -1): Set F = ActiveCell.Offset(0, 1)
If Len(D) = 0 Or Len(F) = 0 Then E = ""
If Len(F) > 0 Then
Dim result As Double
result = Evaluate("=" & D & "/" & F & "*SIN(ACOS(" & F & "))")
E = result
End If
End Function
Function F()
Dim D As Range, E As Range
Set D = ActiveCell.Offset(0, -2): Set E = ActiveCell.Offset(0, -1)
If Len(D) = 0 Or Len(E) = 0 Then F = ""
If Len(E) > 0 Then
Dim result As Double
result = Evaluate("=" & D & "/SQRT((" & D & "^2+" & E & "^2))")
F = result
End If
End Function
- 回到您的電子表格,然後輸入新的公式
- 細胞
E2
現在是=E()
和細胞F2
現在是=F()
拖式 下來
結束了
更新:
要自動化插入和計算
在Project Explorer
»右鍵單擊Sheet1
» View Code
插入下面的代碼
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 5 Then
FillF Target
ElseIf Target.Column = 6 Then
FillE Target
End If
End Sub
在Module1
取代你有以下
Option Explicit
Sub FillF(ByVal Target As Range)
Dim D As Range, E As Range, F As Range
Set E = Target
Set D = E.Offset(0, -1)
Set F = E.Offset(0, 1)
If Not IsError(E) Then
If Len(E) = 0 Then
Exit Sub
ElseIf Len(D) = 0 Then
Exit Sub
ElseIf Len(D) > 0 And Len(F) = 0 Then
F.Formula = "=" & D & "/SQRT((" & D & "^2+" & E & "^2))"
Exit Sub
Else
Exit Sub
End If
Else
F.ClearContents
End If
End Sub
Sub FillE(ByVal Target As Range)
Dim D As Range, E As Range, F As Range
Set F = Target
Set E = F.Offset(0, -1)
Set D = F.Offset(0, -2)
If Not IsError(F) Then
If Len(F) = 0 Then
Exit Sub
ElseIf Len(D) = 0 Then
Exit Sub
ElseIf Len(D) > 0 And Len(E) = 0 Then
E.Formula = "=" & D & "/" & F & "*SIN(ACOS(" & F & "))"
Exit Sub
Else
Exit Sub
End If
Else
E.ClearContents
End If
End Sub
現在的一個代碼,轉到您的電子表格,並輸入一個數字無論是在列E或F,其他公式應計算,並將結果顯示在相鄰的小區。
您可以使用兩個UDF,= E()和= F()。什麼是您要在E或F中輸入的樣本 – 2013-08-16 09:36:09
某些正數。通常E爲67.3,或F爲0.85。 –