ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   E12 conversion (https://www.excelbanter.com/excel-programming/305954-e12-conversion.html)

Valex

E12 conversion
 
Hi All,

Do somebody know a simple user function converting calulated resisto
value to nearest E12 standard one.

Thaks in advance:confused

--
Message posted from http://www.ExcelForum.com


Valex[_2_]

E12 conversion
 
Thanks Guys

After very useful help advices I realize I have to do it myself.
Former Basic user, never build any code this is wath I have done.
Enjoy.


Function CnvSt(InVal As Double)
' My DIY function converting any calculated value capacitor
' or resistor to standard E12 row value

Dim A As Variant, Ras, K, CntM, CntD
Ras = 10000000000#: ContM = 0: CountD = 0
A = Array(1, 1.2, 1.5, 1.8 , 2.2, 2.7, 3.3, 4.7, 5.6, 6.8, 8.2)
InValM = InVal:

'for numbers over 10
If InVal 10 Then
Do While InValM 10
InValM = InValM / 10
CntM = CntM + 1
Loop
End If

' for numbers below 1
If InVal < 1 Then
Do While InValM < 1
InValM = InValM * 10
CntD = CntD + 1
Loop
End If

For j = 0 To 10
If Abs(InValM - A(j)) < Ras Then
Ras = Abs(InValM - A(j))
K = j
End If
Next j
OpVal = A(K) * 10 ^ (CntM) * 10 ^ ((-1) * CntD)
CnvSt = OpVal

End Functio

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 10:38 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com